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_ADTS_H_ | 5 #ifndef MEDIA_FORMATS_MP2T_ES_PARSER_MPEG1AUDIO_H_ |
6 #define MEDIA_FORMATS_MP2T_ES_PARSER_ADTS_H_ | 6 #define MEDIA_FORMATS_MP2T_ES_PARSER_MPEG1AUDIO_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "media/base/audio_decoder_config.h" | 15 #include "media/base/audio_decoder_config.h" |
16 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
17 #include "media/formats/mp2t/es_parser.h" | 17 #include "media/formats/mp2t/es_parser.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 class AudioTimestampHelper; | 20 class AudioTimestampHelper; |
21 class BitReader; | 21 class BitReader; |
22 class OffsetByteQueue; | 22 class OffsetByteQueue; |
23 class StreamParserBuffer; | 23 class StreamParserBuffer; |
24 } | 24 } |
25 | 25 |
26 namespace media { | 26 namespace media { |
27 namespace mp2t { | 27 namespace mp2t { |
28 | 28 |
29 class MEDIA_EXPORT EsParserAdts : public EsParser { | 29 class MEDIA_EXPORT EsParserMpeg1Audio : public EsParser { |
30 public: | 30 public: |
31 typedef base::Callback<void(const AudioDecoderConfig&)> NewAudioConfigCB; | 31 typedef base::Callback<void(const AudioDecoderConfig&)> NewAudioConfigCB; |
32 | 32 |
33 EsParserAdts(const NewAudioConfigCB& new_audio_config_cb, | 33 EsParserMpeg1Audio(const NewAudioConfigCB& new_audio_config_cb, |
34 const EmitBufferCB& emit_buffer_cb, | 34 const EmitBufferCB& emit_buffer_cb); |
35 bool sbr_in_mimetype); | 35 virtual ~EsParserMpeg1Audio(); |
36 virtual ~EsParserAdts(); | |
37 | 36 |
38 // EsParser implementation. | 37 // EsParser implementation. |
39 virtual bool Parse(const uint8* buf, int size, | 38 virtual bool Parse(const uint8* buf, int size, |
40 base::TimeDelta pts, | 39 base::TimeDelta pts, |
41 DecodeTimestamp dts) OVERRIDE; | 40 DecodeTimestamp dts) OVERRIDE; |
42 virtual void Flush() OVERRIDE; | 41 virtual void Flush() OVERRIDE; |
43 virtual void Reset() OVERRIDE; | 42 virtual void Reset() OVERRIDE; |
44 | 43 |
45 private: | 44 private: |
46 // Used to link a PTS with a byte position in the ES stream. | 45 // Used to link a PTS with a byte position in the ES stream. |
47 typedef std::pair<int64, base::TimeDelta> EsPts; | 46 typedef std::pair<int64, base::TimeDelta> EsPts; |
48 typedef std::list<EsPts> EsPtsList; | 47 typedef std::list<EsPts> EsPtsList; |
49 | 48 |
50 struct AdtsFrame; | 49 struct Mpeg1AudioFrame; |
51 | 50 |
52 // Synchronize the stream on an ADTS syncword (consuming bytes from | 51 // Synchronize the stream on a Mpeg1 audio syncword (consuming bytes from |
53 // |es_queue_| if needed). | 52 // |es_queue_| if needed). |
54 // Returns true when a full ADTS frame has been found: in that case | 53 // Returns true when a full Mpeg1 audio frame has been found: in that case |
55 // |adts_frame| structure is filled up accordingly. | 54 // |mpeg1audio_frame| structure is filled up accordingly. |
56 // Returns false otherwise (no ADTS syncword found or partial ADTS frame). | 55 // Returns false otherwise (no Mpeg1 audio syncword found or partial Mpeg1 |
57 bool LookForAdtsFrame(AdtsFrame* adts_frame); | 56 // audio frame). |
58 | 57 bool LookForMpeg1AudioFrame(Mpeg1AudioFrame* mpeg1audio_frame); |
59 // Skip an ADTS frame in the ES queue. | |
60 void SkipAdtsFrame(const AdtsFrame& adts_frame); | |
61 | 58 |
62 // Signal any audio configuration change (if any). | 59 // Signal any audio configuration change (if any). |
63 // Return false if the current audio config is not | 60 // Return false if the current audio config is not |
64 // a supported ADTS audio config. | 61 // a supported Mpeg1 audio config. |
65 bool UpdateAudioConfiguration(const uint8* adts_header); | 62 bool UpdateAudioConfiguration(const uint8* mpeg1audio_header); |
| 63 |
| 64 void SkipMpeg1AudioFrame(const Mpeg1AudioFrame& mpeg1audio_frame); |
66 | 65 |
67 // Callbacks: | 66 // Callbacks: |
68 // - to signal a new audio configuration, | 67 // - to signal a new audio configuration, |
69 // - to send ES buffers. | 68 // - to send ES buffers. |
70 NewAudioConfigCB new_audio_config_cb_; | 69 NewAudioConfigCB new_audio_config_cb_; |
71 EmitBufferCB emit_buffer_cb_; | 70 EmitBufferCB emit_buffer_cb_; |
72 | 71 |
73 // True when AAC SBR extension is signalled in the mimetype | |
74 // (mp4a.40.5 in the codecs parameter). | |
75 bool sbr_in_mimetype_; | |
76 | |
77 // Bytes of the ES stream that have not been emitted yet. | 72 // Bytes of the ES stream that have not been emitted yet. |
78 scoped_ptr<media::OffsetByteQueue> es_queue_; | 73 scoped_ptr<media::OffsetByteQueue> es_queue_; |
79 | 74 |
80 // List of PTS associated with a position in the ES stream. | 75 // List of PTS associated with a position in the ES stream. |
81 EsPtsList pts_list_; | 76 EsPtsList pts_list_; |
82 | 77 |
83 // Interpolated PTS for frames that don't have one. | 78 // Interpolated PTS for frames that don't have one. |
84 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_; | 79 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_; |
85 | 80 |
86 // Last audio config. | 81 // Last audio config. |
87 AudioDecoderConfig last_audio_decoder_config_; | 82 AudioDecoderConfig last_audio_decoder_config_; |
88 | 83 |
89 DISALLOW_COPY_AND_ASSIGN(EsParserAdts); | 84 DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1Audio); |
90 }; | 85 }; |
91 | 86 |
92 } // namespace mp2t | 87 } // namespace mp2t |
93 } // namespace media | 88 } // namespace media |
94 | 89 |
95 #endif | 90 #endif // MEDIA_FORMATS_MP2T_ES_PARSER_MPEG1AUDIO_H_ |
OLD | NEW |