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