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_MP2T_MP2T_STREAM_PARSER_H_ |
| 6 #define MEDIA_MP2T_MP2T_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 StreamParserBuffer; |
| 22 |
| 23 namespace mp2t { |
| 24 |
| 25 class PidState; |
| 26 |
| 27 class MEDIA_EXPORT Mp2tStreamParser : public StreamParser { |
| 28 public: |
| 29 Mp2tStreamParser(); |
| 30 virtual ~Mp2tStreamParser(); |
| 31 |
| 32 // StreamParser implementation. |
| 33 virtual void Init(const InitCB& init_cb, |
| 34 const NewConfigCB& config_cb, |
| 35 const NewBuffersCB& new_buffers_cb, |
| 36 const NewTextBuffersCB& text_cb, |
| 37 const NeedKeyCB& need_key_cb, |
| 38 const AddTextTrackCB& add_text_track_cb, |
| 39 const NewMediaSegmentCB& new_segment_cb, |
| 40 const base::Closure& end_of_segment_cb, |
| 41 const LogCB& log_cb) OVERRIDE; |
| 42 virtual void Flush() OVERRIDE; |
| 43 virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| 44 |
| 45 private: |
| 46 typedef std::map<int, PidState*> PidMap; |
| 47 |
| 48 struct BufferQueueWithConfig { |
| 49 bool is_config_sent; |
| 50 AudioDecoderConfig audio_config; |
| 51 StreamParser::BufferQueue audio_queue; |
| 52 VideoDecoderConfig video_config; |
| 53 StreamParser::BufferQueue video_queue; |
| 54 }; |
| 55 |
| 56 // Callback invoked to register a Program Map Table. |
| 57 // Note: Does nothing if the PID is already registered. |
| 58 void RegisterPmt(int program_number, int pmt_pid); |
| 59 |
| 60 // Callback invoked to register a PES pid. |
| 61 // Possible values for |stream_type| are defined in: |
| 62 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments". |
| 63 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|. |
| 64 void RegisterPes(int pmt_pid, int pes_pid, int stream_type); |
| 65 |
| 66 // Since the StreamParser interface allows only one audio & video streams, |
| 67 // an automatic PID filtering should be applied to select the audio & video |
| 68 // streams. |
| 69 void UpdatePidFilter(); |
| 70 |
| 71 // Callback invoked each time the audio/video decoder configuration is |
| 72 // changed. |
| 73 void OnVideoConfigChanged(int pes_pid, |
| 74 const VideoDecoderConfig& video_decoder_config); |
| 75 void OnAudioConfigChanged(int pes_pid, |
| 76 const AudioDecoderConfig& audio_decoder_config); |
| 77 |
| 78 // Invoke the initialization callback if needed. |
| 79 bool FinishInitializationIfNeeded(); |
| 80 |
| 81 // Callback invoked by the ES stream parser |
| 82 // to emit a new audio/video access unit. |
| 83 void OnEmitAudioBuffer( |
| 84 int pes_pid, |
| 85 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
| 86 void OnEmitVideoBuffer( |
| 87 int pes_pid, |
| 88 scoped_refptr<StreamParserBuffer> stream_parser_buffer); |
| 89 bool EmitRemainingBuffers(); |
| 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 // Pending audio & video buffers. |
| 111 std::list<BufferQueueWithConfig> buffer_queue_chain_; |
| 112 |
| 113 // Last audio and video decoder config sent. |
| 114 AudioDecoderConfig last_audio_config_; |
| 115 VideoDecoderConfig last_video_config_; |
| 116 |
| 117 // Whether |init_cb_| has been invoked. |
| 118 bool is_initialized_; |
| 119 |
| 120 // Indicate whether a segment was started. |
| 121 bool segment_started_; |
| 122 bool first_video_frame_in_segment_; |
| 123 base::TimeDelta time_offset_; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser); |
| 126 }; |
| 127 |
| 128 } // namespace mp2t |
| 129 } // namespace media |
| 130 |
| 131 #endif |
| 132 |
OLD | NEW |