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

Side by Side Diff: media/filters/chunk_demuxer.h

Issue 7203002: Adding ChunkDemuxer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup & commenting Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 // Implements a Demuxer that can switch among different data sources mid-stream.
6 // Uses FFmpegDemuxer under the covers, so see the caveats at the top of
7 // ffmpeg_demuxer.h.
8
9 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_
10 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_
11
12 #include <list>
13
14 #include "base/synchronization/lock.h"
15 #include "media/base/filter_factories.h"
16 #include "media/base/filters.h"
17 #include "media/filters/webm_parser.h"
18
19 struct AVFormatContext;
20
21 namespace media {
22
23 class ChunkDemuxer;
24 class ChunkDemuxerStream;
25
26 // Class used by WebMediaPlayerImpl to send media data to the
27 // Demuxer. This object is created by the DemuxerFactory and
28 // contains the Demuxer that will be returned in the next Build()
29 // call on the factory. The WebMediaPlayerImpl tells the factory
30 // to create one of these objects before it starts the Pipeline.
31 // It does this because WebMediaPlayerImpl may get AddData()
32 // calls from JavaScript before the pipeline has completely initialized.
33 // This allows data from these calls to be queued until initialization
34 // completes. This class represents the minimal operations needed by
35 // WebMediaPlayerImpl to talk to the Demuxer.
scherkus (not reviewing) 2011/06/22 17:31:09 media doesn't known about WebMediaPlayerImpl this
acolwell GONE FROM CHROMIUM 2011/06/23 16:51:28 Done.
36 class MediaDataSink {
37 public:
38 MediaDataSink(const scoped_refptr<ChunkDemuxer>& demuxer);
39 ~MediaDataSink();
40
41 // Flush all data passed via AddData().
42 void Flush();
43
44 // Sends media data to the demuxer. Returns true if the data is valid.
45 bool AddData(const uint8* data, unsigned length);
46
47 // Signals that playback is shutting down and further AddData() calls
48 // should fail. This also cancels pending Read()s on DemuxerStreams.
49 void Shutdown();
50
51 private:
52 scoped_refptr<ChunkDemuxer> demuxer_;
53 };
54
55 class ChunkDemuxer : public Demuxer {
56 public:
57 ChunkDemuxer();
58 virtual ~ChunkDemuxer();
59
60 bool Init(const uint8* data, int size);
61
62 // Filter implementation.
63 virtual void set_host(FilterHost* filter_host);
64 virtual void Stop(FilterCallback* callback);
65 virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb);
66 virtual void OnAudioRendererDisabled();
67 virtual void SetPreload(Preload preload);
68
69 // Demuxer implementation.
70 virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type);
71 virtual base::TimeDelta GetStartTime() const;
72
73 // Methods used by MediaDataSink
74 void FlushData();
75 bool AddData(const uint8* data, unsigned length);
76 void Shutdown();
77
78 private:
79 // Helper class that collects information from the INFO & TRACKS elements
80 // passed to Init().
81 class InfoTrackWebMParserClient : public WebMParserClient {
82 public:
83 InfoTrackWebMParserClient();
84
85 int64 timecode_scale() const;
86 double duration() const;
87 int64 audio_track_num() const;
88 int64 audio_default_duration() const;
89 int64 video_track_num() const;
90 int64 video_default_duration() const;
91
92 // WebMParserClient methods
93 virtual bool OnListStart(int id);
94 virtual bool OnListEnd(int id);
95 virtual bool OnUInt(int id, int64 val);
96 virtual bool OnFloat(int id, double val);
97 virtual bool OnBinary(int id, const uint8* data, int size);
98 virtual bool OnString(int id, const std::string& str);
99 virtual bool OnSimpleBlock(int track_num, int timecode,
100 int flags,
101 const uint8* data, int size);
102 private:
103 int64 timecode_scale_;
104 double duration_;
105 int64 track_type_;
106 int64 track_num_;
107 int64 track_default_duration_;
108 int64 audio_track_num_;
109 int64 audio_default_duration_;
110 int64 video_track_num_;
111 int64 video_default_duration_;
112 };
113
114 enum State {
115 WAITING_FOR_INIT,
116 INITIALIZED,
117 INIT_ERROR,
118 SHUTDOWN,
119 };
120
121 void ChangeState(State new_state);
122
123 // Generates an AVFormatContext for the INFO & TRACKS elements contained
124 // in |data|. Returns NULL if parsing |data| fails.
125 AVFormatContext* CreateFormatContext(const uint8* data, int size) const;
126
127 // Sets up |audio_| & |video_| DemuxerStreams based on the data in
128 // |format_context_|. Returns false if no valid audio or video stream were
129 // found.
130 bool SetupStreams();
131
132 // Parse all the buffers in |pending_buffers_|. Returns false if parsing one
133 // of the buffers fails.
134 bool ParsePendingBuffers();
135
136 // Parse a buffer that was passed to AddData(). |data| is expected to contain
137 // one or more WebM Clusters. Returns false if parsing the data fails.
138 bool ParseAndAddData_Locked(const uint8* data, int length);
139
140 base::Lock lock_;
141 State state_;
142
143 base::TimeDelta seek_time_;
144 FilterStatusCB seek_cb_;
145
146 scoped_refptr<ChunkDemuxerStream> audio_;
147 scoped_refptr<ChunkDemuxerStream> video_;
148
149 AVFormatContext* format_context_;
150
151 int64 buffered_bytes_;
152
153 bool first_seek_;
154 base::TimeDelta duration_;
155
156 InfoTrackWebMParserClient info_;
157
158 typedef std::list<scoped_refptr<media::Buffer> > BufferList;
159 BufferList pending_buffers_;
160
161 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer);
162 };
163
164 class ChunkDemuxerFactory : public DemuxerFactory {
165 public:
166 // Takes a reference to |demuxer_factory|.
167 ChunkDemuxerFactory(DataSourceFactory* data_source_factory);
168 virtual ~ChunkDemuxerFactory();
169
170 bool IsUrlSupported(const std::string& url) const;
171 MediaDataSink* CreateMediaDataSink();
172
173 // DemuxerFactory methods.
174 virtual void Build(const std::string& url, BuildCallback* cb);
175 virtual DemuxerFactory* Clone() const;
176
177 private:
178 static const char kURLPrefix[];
179 class BuildState;
180
181 scoped_ptr<DataSourceFactory> data_source_factory_;
182 scoped_refptr<ChunkDemuxer> demuxer_;
183
184 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerFactory);
185 };
186
187 } // namespace media
188
189 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698