Chromium Code Reviews| 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_FORMATS_MP2T_ES_PARSER_H_ | 5 #ifndef MEDIA_FORMATS_MP2T_ES_PARSER_H_ |
| 6 #define MEDIA_FORMATS_MP2T_ES_PARSER_H_ | 6 #define MEDIA_FORMATS_MP2T_ES_PARSER_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <utility> | |
| 10 | |
| 8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 12 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 11 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 12 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 13 #include "media/base/stream_parser_buffer.h" | 16 #include "media/base/stream_parser_buffer.h" |
| 14 | 17 |
| 15 namespace media { | 18 namespace media { |
| 16 | 19 |
| 20 class OffsetByteQueue; | |
| 17 class StreamParserBuffer; | 21 class StreamParserBuffer; |
| 18 | 22 |
| 19 namespace mp2t { | 23 namespace mp2t { |
| 20 | 24 |
| 21 class MEDIA_EXPORT EsParser { | 25 class MEDIA_EXPORT EsParser { |
| 22 public: | 26 public: |
| 23 typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB; | 27 typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB; |
| 24 | 28 |
| 25 EsParser() {} | 29 EsParser(); |
| 26 virtual ~EsParser() {} | 30 virtual ~EsParser(); |
| 27 | 31 |
| 28 // ES parsing. | 32 // ES parsing. |
| 29 // Should use kNoTimestamp when a timestamp is not valid. | 33 // Should use kNoTimestamp when a timestamp is not valid. |
| 30 virtual bool Parse(const uint8* buf, int size, | 34 bool Parse(const uint8* buf, int size, |
| 31 base::TimeDelta pts, | 35 base::TimeDelta pts, |
| 32 DecodeTimestamp dts) = 0; | 36 DecodeTimestamp dts); |
| 33 | 37 |
| 34 // Flush any pending buffer. | 38 // Flush any pending buffer. |
| 35 virtual void Flush() = 0; | 39 virtual void Flush() = 0; |
| 36 | 40 |
| 37 // Reset the state of the ES parser. | 41 // Reset the state of the ES parser. |
| 38 virtual void Reset() = 0; | 42 void Reset(); |
| 43 | |
| 44 protected: | |
| 45 struct TimingDesc { | |
| 46 TimingDesc(); | |
| 47 TimingDesc(DecodeTimestamp dts, base::TimeDelta pts); | |
| 48 | |
| 49 DecodeTimestamp dts; | |
| 50 base::TimeDelta pts; | |
| 51 }; | |
| 52 | |
| 53 // Parse ES data from |es_queue_|. | |
| 54 // Return true when successful. | |
| 55 virtual bool ParseFromEsQueue() = 0; | |
|
damienv1
2014/08/27 16:37:21
Maybe at some point, we should consider making EsP
wolenetz
2014/08/27 18:23:02
I have no strong feeling here. For now, derivation
| |
| 56 | |
| 57 // Reset the internal state of the ES parser. | |
| 58 virtual void ResetInternal() = 0; | |
| 59 | |
| 60 // Get the timing descriptor with the largest byte count that is less or | |
| 61 // equal to |es_byte_count|. | |
| 62 // This timing descriptor and all the ones that come before (in stream order) | |
| 63 // are removed from list |timing_desc_list_|. | |
| 64 // If no timing descriptor is found, then the default TimingDesc is returned. | |
| 65 TimingDesc GetTimingDescriptor(int64 es_byte_count); | |
| 66 | |
| 67 // Bytes of the ES stream that have not been emitted yet. | |
| 68 scoped_ptr<media::OffsetByteQueue> es_queue_; | |
| 69 | |
| 70 private: | |
| 71 // Anchor some timing information into the ES queue. | |
| 72 // Here are two examples how this timing info is applied according to | |
| 73 // the MPEG-2 TS spec - ISO/IEC 13818: | |
| 74 // - "In the case of audio, if a PTS is present in PES packet header it shall | |
| 75 // refer to the first access unit commencing in the PES packet. An audio | |
| 76 // access unit commences in a PES packet if the first byte of the audio | |
| 77 // access unit is present in the PES packet." | |
| 78 // - "For AVC video streams conforming to one or more profiles defined | |
| 79 // in Annex A of Rec. ITU-T H.264 | ISO/IEC 14496-10 video, if a PTS is | |
| 80 // present in the PES packet header, it shall refer to the first AVC access | |
| 81 // unit that commences in this PES packet. | |
| 82 std::list<std::pair<int64, TimingDesc> > timing_desc_list_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(EsParser); | |
| 39 }; | 85 }; |
| 40 | 86 |
| 41 } // namespace mp2t | 87 } // namespace mp2t |
| 42 } // namespace media | 88 } // namespace media |
| 43 | 89 |
| 44 #endif | 90 #endif |
| OLD | NEW |