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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FORMATS_MP2T_ES_PARSER_MPEG1AUDIO_H_
6 #define MEDIA_FORMATS_MP2T_ES_PARSER_MPEG1AUDIO_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "media/base/audio_decoder_config.h"
16 #include "media/base/media_export.h"
17 #include "media/base/media_log.h"
18 #include "media/formats/mp2t/es_parser.h"
21 class AudioTimestampHelper
;
23 class OffsetByteQueue
;
24 class StreamParserBuffer
;
30 class MEDIA_EXPORT EsParserMpeg1Audio
: public EsParser
{
32 typedef base::Callback
<void(const AudioDecoderConfig
&)> NewAudioConfigCB
;
34 EsParserMpeg1Audio(const NewAudioConfigCB
& new_audio_config_cb
,
35 const EmitBufferCB
& emit_buffer_cb
,
37 ~EsParserMpeg1Audio() override
;
39 // EsParser implementation.
40 void Flush() override
;
43 // Used to link a PTS with a byte position in the ES stream.
44 typedef std::pair
<int64
, base::TimeDelta
> EsPts
;
45 typedef std::list
<EsPts
> EsPtsList
;
47 struct Mpeg1AudioFrame
;
49 // EsParser implementation.
50 bool ParseFromEsQueue() override
;
51 void ResetInternal() override
;
53 // Synchronize the stream on a Mpeg1 audio syncword (consuming bytes from
54 // |es_queue_| if needed).
55 // Returns true when a full Mpeg1 audio frame has been found: in that case
56 // |mpeg1audio_frame| structure is filled up accordingly.
57 // Returns false otherwise (no Mpeg1 audio syncword found or partial Mpeg1
59 bool LookForMpeg1AudioFrame(Mpeg1AudioFrame
* mpeg1audio_frame
);
61 // Signal any audio configuration change (if any).
62 // Return false if the current audio config is not
63 // a supported Mpeg1 audio config.
64 bool UpdateAudioConfiguration(const uint8
* mpeg1audio_header
);
66 void SkipMpeg1AudioFrame(const Mpeg1AudioFrame
& mpeg1audio_frame
);
71 // - to signal a new audio configuration,
72 // - to send ES buffers.
73 NewAudioConfigCB new_audio_config_cb_
;
74 EmitBufferCB emit_buffer_cb_
;
76 // Interpolated PTS for frames that don't have one.
77 scoped_ptr
<AudioTimestampHelper
> audio_timestamp_helper_
;
80 AudioDecoderConfig last_audio_decoder_config_
;
82 DISALLOW_COPY_AND_ASSIGN(EsParserMpeg1Audio
);
88 #endif // MEDIA_FORMATS_MP2T_ES_PARSER_MPEG1AUDIO_H_