| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_CAST_LOGGING_LOG_SERIALIZER_H_ | 5 #ifndef MEDIA_CAST_LOGGING_LOG_SERIALIZER_H_ |
| 6 #define MEDIA_CAST_LOGGING_LOG_SERIALIZER_H_ | 6 #define MEDIA_CAST_LOGGING_LOG_SERIALIZER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "media/cast/logging/encoding_event_subscriber.h" | 11 #include "media/cast/logging/encoding_event_subscriber.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 namespace cast { | 14 namespace cast { |
| 15 | 15 |
| 16 // The max allowed size of serialized log. | 16 // Serialize |frame_events|, |packet_events|, |log_metadata| |
| 17 const int kMaxSerializedLogBytes = 20 * 1000 * 1000; | 17 // returned from EncodingEventSubscriber. |
| 18 | 18 // Result is written to |output|, which can hold |max_output_bytes| of data. |
| 19 // This class takes FrameEventMap and PacketEventMap returned from an | 19 // If |compress| is true, |output| will be set with data compresssed in |
| 20 // EncodingEventSubscriber and serialize them. An instance of this class | 20 // gzip format. |
| 21 // can take input from multiple EncodingEventSubscribers (which represents | 21 // |output_bytes| will be set to number of bytes written. |
| 22 // different streams). | 22 // |
| 23 // Usage: | 23 // Returns |true| if serialization is successful. This function |
| 24 // 1. Construct a LogSerializer with a predefined maximum serialized length. | 24 // returns |false| if the serialized string will exceed |max_output_bytes|. |
| 25 // 2. For each set of FrameEventMap and PacketEventMap returned by | 25 // |
| 26 // EncodingEventSubscriber installed on each stream, call | 26 // See .cc file for format specification. |
| 27 // |SerializeEventsForStream()| along with the stream id. Check the returned | 27 bool SerializeEvents(const media::cast::proto::LogMetadata& log_metadata, |
| 28 // value to see if serialization succeeded. | 28 const FrameEventMap& frame_events, |
| 29 // 3. Call |GetSerializedLogAndReset()| to get the result. | 29 const PacketEventMap& packet_events, |
| 30 // 4. (Optional) Call |GetSerializedLengthSoFar()| between each serialize call. | 30 bool compress, |
| 31 class LogSerializer { | 31 int max_output_bytes, |
| 32 public: | 32 char* output, |
| 33 // Constructs a LogSerializer that caps size of serialized message to | 33 int* output_bytes); |
| 34 // |max_serialized_bytes|. | |
| 35 explicit LogSerializer(const int max_serialized_bytes); | |
| 36 ~LogSerializer(); | |
| 37 | |
| 38 // Serialize |frame_events|, |packet_events|, and |metadata| | |
| 39 // returned from EncodingEventSubscriber. | |
| 40 // | |
| 41 // Returns |true| if serialization is successful. This function | |
| 42 // returns |false| if the serialized string will exceed |kMaxSerializedsize|. | |
| 43 // | |
| 44 // This may be called multiple times with different streams and events before | |
| 45 // calling |GetSerializedString()|. | |
| 46 // | |
| 47 // See .cc file for format specification. | |
| 48 bool SerializeEventsForStream(const media::cast::proto::LogMetadata& metadata, | |
| 49 const FrameEventMap& frame_events, | |
| 50 const PacketEventMap& packet_events); | |
| 51 | |
| 52 // Gets a string of serialized events up to the last successful call to | |
| 53 // |SerializeEventsForStream()| and resets it. | |
| 54 scoped_ptr<std::string> GetSerializedLogAndReset(); | |
| 55 | |
| 56 // Returns the length of the serialized string since last | |
| 57 // successful serialization / reset. | |
| 58 int GetSerializedLength() const; | |
| 59 | |
| 60 private: | |
| 61 scoped_ptr<std::string> serialized_log_so_far_; | |
| 62 int index_so_far_; | |
| 63 const int max_serialized_bytes_; | |
| 64 }; | |
| 65 | 34 |
| 66 } // namespace cast | 35 } // namespace cast |
| 67 } // namespace media | 36 } // namespace media |
| 68 | 37 |
| 69 #endif // MEDIA_CAST_LOGGING_LOG_SERIALIZER_H_ | 38 #endif // MEDIA_CAST_LOGGING_LOG_SERIALIZER_H_ |
| OLD | NEW |