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 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
| 6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/synchronization/lock.h" |
| 11 #include "media/base/filters.h" |
| 12 #include "media/webm/webm_cluster_parser.h" |
| 13 |
| 14 struct AVFormatContext; |
| 15 |
| 16 namespace media { |
| 17 |
| 18 class ChunkDemuxerStream; |
| 19 |
| 20 // Demuxer implementation that allows chunks of WebM media data to be passed |
| 21 // from JavaScript to the media stack. |
| 22 class ChunkDemuxer : public Demuxer { |
| 23 public: |
| 24 ChunkDemuxer(); |
| 25 virtual ~ChunkDemuxer(); |
| 26 |
| 27 bool Init(const uint8* data, int size); |
| 28 |
| 29 // Filter implementation. |
| 30 virtual void set_host(FilterHost* filter_host); |
| 31 virtual void Stop(FilterCallback* callback); |
| 32 virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb); |
| 33 virtual void OnAudioRendererDisabled(); |
| 34 virtual void SetPreload(Preload preload); |
| 35 |
| 36 // Demuxer implementation. |
| 37 virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type); |
| 38 virtual base::TimeDelta GetStartTime() const; |
| 39 |
| 40 // Methods used by MediaDataSink |
| 41 void FlushData(); |
| 42 bool AddData(const uint8* data, unsigned length); |
| 43 void Shutdown(); |
| 44 |
| 45 private: |
| 46 enum State { |
| 47 WAITING_FOR_INIT, |
| 48 INITIALIZED, |
| 49 INIT_ERROR, |
| 50 SHUTDOWN, |
| 51 }; |
| 52 |
| 53 void ChangeState(State new_state); |
| 54 |
| 55 // Generates an AVFormatContext for the INFO & TRACKS elements contained |
| 56 // in |data|. Returns NULL if parsing |data| fails. |
| 57 AVFormatContext* CreateFormatContext(const uint8* data, int size) const; |
| 58 |
| 59 // Sets up |audio_| & |video_| DemuxerStreams based on the data in |
| 60 // |format_context_|. Returns false if no valid audio or video stream were |
| 61 // found. |
| 62 bool SetupStreams(); |
| 63 |
| 64 // Parse all the buffers in |pending_buffers_|. Returns false if parsing one |
| 65 // of the buffers fails. |
| 66 bool ParsePendingBuffers(); |
| 67 |
| 68 // Parse a buffer that was passed to AddData(). |data| is expected to contain |
| 69 // one or more WebM Clusters. Returns false if parsing the data fails. |
| 70 bool ParseAndAddData_Locked(const uint8* data, int length); |
| 71 |
| 72 base::Lock lock_; |
| 73 State state_; |
| 74 |
| 75 FilterStatusCB seek_cb_; |
| 76 |
| 77 scoped_refptr<ChunkDemuxerStream> audio_; |
| 78 scoped_refptr<ChunkDemuxerStream> video_; |
| 79 |
| 80 AVFormatContext* format_context_; |
| 81 |
| 82 int64 buffered_bytes_; |
| 83 |
| 84 base::TimeDelta duration_; |
| 85 |
| 86 scoped_ptr<WebMClusterParser> cluster_parser_; |
| 87 |
| 88 typedef std::list<scoped_refptr<media::Buffer> > BufferList; |
| 89 BufferList pending_buffers_; |
| 90 |
| 91 // Should a Seek() call wait for more data before calling the |
| 92 // callback. |
| 93 bool seek_waits_for_data_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
| 96 }; |
| 97 |
| 98 } // namespace media |
| 99 |
| 100 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |