Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: media/mp2t/mp2t_stream_parser.h

Issue 23566013: Mpeg2 TS stream parser for media source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 class AudioBufferWithConfig;
49 class VideoBufferWithConfig;
50
51 // Callback invoked to register a Program Map Table.
52 // Note: Does nothing if the PID is already registered.
53 void RegisterPmt(int program_number, int pmt_pid);
54
55 // Callback invoked to register a PES pid.
56 // Possible values for |stream_type| are defined in:
57 // ISO-13818.1 / ITU H.222 Table 2.34 "Stream type assignments".
58 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
59 void RegisterPes(int pmt_pid, int pes_pid, int stream_type);
60
61 // Since the StreamParser interface allows only one audio & video streams,
62 // an automatic PID filtering should be applied to select the audio & video
63 // streams.
64 void UpdatePidFilter();
65
66 // Callback invoked each time the audio/video decoder configuration is
67 // changed.
68 void OnVideoConfigChanged(int pes_pid,
69 const VideoDecoderConfig& video_decoder_config);
70 void OnAudioConfigChanged(int pes_pid,
71 const AudioDecoderConfig& audio_decoder_config);
72
73 // Invoke the initialization callback if needed.
74 void FinishInitializationIfNeeded();
75
76 // Callback invoked by the ES stream parser
77 // to emit a new audio/video access unit.
78 void OnEmitAudioBuffer(
79 int pes_pid,
80 scoped_refptr<StreamParserBuffer> stream_parser_buffer);
81 void OnEmitVideoBuffer(
82 int pes_pid,
83 scoped_refptr<StreamParserBuffer> stream_parser_buffer);
84
85 void EmitRemainingBuffers();
86 AudioDecoderConfig GetAudioBuffers(BufferQueue* video_queue);
87 VideoDecoderConfig GetVideoBuffers(BufferQueue* video_queue);
88
89 // List of callbacks.
90 InitCB init_cb_;
91 NewConfigCB config_cb_;
92 NewBuffersCB new_buffers_cb_;
93 NeedKeyCB need_key_cb_;
94 NewMediaSegmentCB new_segment_cb_;
95 base::Closure end_of_segment_cb_;
96 LogCB log_cb_;
97
98 // Bytes of the TS stream.
99 ByteQueue ts_byte_queue_;
100
101 // List of PIDs and their state.
102 PidMap pids_;
103
104 // Selected audio and video PIDs.
105 int selected_audio_pid_;
106 int selected_video_pid_;
107
108 // Audio & video decoder config that applies to upcoming buffers.
109 AudioDecoderConfig audio_config_;
110 VideoDecoderConfig video_config_;
111
112 // Pending audio & video buffers.
113 std::list<AudioBufferWithConfig> audio_buffer_queue_;
114 std::list<VideoBufferWithConfig> video_buffer_queue_;
115
116 // Audio and Video decoder config of the last emitted buffers.
117 AudioDecoderConfig last_audio_config_;
118 VideoDecoderConfig last_video_config_;
119
120 // Whether |init_cb_| has been invoked.
121 bool is_initialized_;
122
123 // Indicate whether a segment was started.
124 bool segment_started_;
125 bool first_video_frame_in_segment_;
126 base::TimeDelta time_offset_;
127
128 DISALLOW_COPY_AND_ASSIGN(Mp2tStreamParser);
129 };
130
131 } // namespace mp2t
132 } // namespace media
133
134 #endif
135
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698