OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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. |
| 4 |
| 5 #ifndef MEDIA_MPEG2_MPEG2TS_STREAM_PARSER_H_ |
| 6 #define MEDIA_MPEG2_MPEG2TS_STREAM_PARSER_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <map> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "media/base/audio_decoder_config.h" |
| 14 #include "media/base/byte_queue.h" |
| 15 #include "media/base/media_export.h" |
| 16 #include "media/base/stream_parser.h" |
| 17 #include "media/base/video_decoder_config.h" |
| 18 |
| 19 namespace media { |
| 20 |
| 21 class AudioDecoderConfig; |
| 22 class StreamParserBuffer; |
| 23 class VideoDecoderConfig; |
| 24 |
| 25 namespace mpeg2ts { |
| 26 |
| 27 class PidState; |
| 28 |
| 29 class MEDIA_EXPORT Mpeg2TsStreamParser : public StreamParser { |
| 30 public: |
| 31 Mpeg2TsStreamParser(); |
| 32 virtual ~Mpeg2TsStreamParser(); |
| 33 |
| 34 // StreamParser implementation. |
| 35 virtual void Init(const InitCB& init_cb, |
| 36 const NewConfigCB& config_cb, |
| 37 const NewBuffersCB& new_buffers_cb, |
| 38 const NewTextBuffersCB& text_cb, |
| 39 const NeedKeyCB& need_key_cb, |
| 40 const AddTextTrackCB& add_text_track_cb, |
| 41 const NewMediaSegmentCB& new_segment_cb, |
| 42 const base::Closure& end_of_segment_cb, |
| 43 const LogCB& log_cb) OVERRIDE; |
| 44 virtual void Flush() OVERRIDE; |
| 45 virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| 46 |
| 47 private: |
| 48 typedef std::map<int, PidState*> PidMap; |
| 49 |
| 50 class AudioBufferWithConfig; |
| 51 class VideoBufferWithConfig; |
| 52 |
| 53 // Callback invoked to register a Program Map Table. |
| 54 // Note: Does nothing if the PID is already registered. |
| 55 void RegisterPmt(int program_number, int pmt_pid); |
| 56 |
| 57 // Callback invoked to register a PES pid. |
| 58 // Possible values for |stream_type| are defined in: |
| 59 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments". |
| 60 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. |
| 61 void RegisterPes(int pmt_pid, int pes_pid, int stream_type); |
| 62 |
| 63 // Since the StreamParser interface allows only one audio & video streams, |
| 64 // an automatic PID filtering should be applied to select the audio & video |
| 65 // streams. |
| 66 void UpdatePidFilter(); |
| 67 |
| 68 // Callback invoked each time the audio/video decoder configuration is |
| 69 // changing. |
| 70 void OnVideoConfigChanged(int pes_pid, |
| 71 const VideoDecoderConfig& video_decoder_config); |
| 72 void OnAudioConfigChanged(int pes_pid, |
| 73 const AudioDecoderConfig& audio_decoder_config); |
| 74 |
| 75 // Invoke the initialization callback if needed. |
| 76 void FinishInitializationIfNeeded(); |
| 77 |
| 78 // Callback invoked by the ES stream parser |
| 79 // to emit a new audio/video access unit. |
| 80 void OnEmitAudioBuffer( |
| 81 int pes_pid, |
| 82 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
| 83 void OnEmitVideoBuffer( |
| 84 int pes_pid, |
| 85 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
| 86 |
| 87 void EmitRemainingBuffers(); |
| 88 void EmitAudioBuffers(); |
| 89 void EmitVideoBuffers(); |
| 90 |
| 91 // List of callbacks. |
| 92 InitCB init_cb_; |
| 93 NewConfigCB config_cb_; |
| 94 NewBuffersCB new_buffers_cb_; |
| 95 NeedKeyCB need_key_cb_; |
| 96 NewMediaSegmentCB new_segment_cb_; |
| 97 base::Closure end_of_segment_cb_; |
| 98 LogCB log_cb_; |
| 99 |
| 100 // Bytes of the TS stream. |
| 101 ByteQueue ts_byte_queue_; |
| 102 |
| 103 // List of PIDs and their state. |
| 104 PidMap pids_; |
| 105 |
| 106 // Selected audio and video PIDs. |
| 107 int selected_audio_pid_; |
| 108 int selected_video_pid_; |
| 109 |
| 110 // Audio & video decoder config that applies to upcoming buffers. |
| 111 AudioDecoderConfig audio_config_; |
| 112 VideoDecoderConfig video_config_; |
| 113 |
| 114 // Pending audio & video buffers. |
| 115 std::list<AudioBufferWithConfig> audio_buffer_queue_; |
| 116 std::list<VideoBufferWithConfig> video_buffer_queue_; |
| 117 |
| 118 // Audio and Video decoder config of the last emitted buffers. |
| 119 AudioDecoderConfig last_audio_config_; |
| 120 VideoDecoderConfig last_video_config_; |
| 121 |
| 122 // Whether |init_cb_| has been invoked. |
| 123 bool is_initialized_; |
| 124 |
| 125 // Indicate whether a segment was started. |
| 126 bool segment_started_; |
| 127 base::TimeDelta time_offset_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(Mpeg2TsStreamParser); |
| 130 }; |
| 131 |
| 132 } // namespace mpeg2ts |
| 133 } // namespace media |
| 134 |
| 135 #endif |
| 136 |
OLD | NEW |