| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 5 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
| 6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | |
| 10 | 9 |
| 11 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 12 #include "media/base/byte_queue.h" | 11 #include "media/base/byte_queue.h" |
| 13 #include "media/base/demuxer.h" | 12 #include "media/base/demuxer.h" |
| 14 #include "media/base/stream_parser.h" | 13 #include "media/base/stream_parser.h" |
| 15 | 14 |
| 16 namespace media { | 15 namespace media { |
| 17 | 16 |
| 18 class ChunkDemuxerClient; | 17 class ChunkDemuxerClient; |
| 19 class ChunkDemuxerStream; | 18 class ChunkDemuxerStream; |
| 20 class FFmpegURLProtocol; | 19 class FFmpegURLProtocol; |
| 21 | 20 |
| 22 // Demuxer implementation that allows chunks of media data to be passed | 21 // Demuxer implementation that allows chunks of media data to be passed |
| 23 // from JavaScript to the media stack. | 22 // from JavaScript to the media stack. |
| 24 class MEDIA_EXPORT ChunkDemuxer : public Demuxer, public StreamParserHost { | 23 class MEDIA_EXPORT ChunkDemuxer : public Demuxer, public StreamParserHost { |
| 25 public: | 24 public: |
| 26 enum Status { | |
| 27 kOk, // ID added w/o error. | |
| 28 kNotSupported, // Type specified is not supported. | |
| 29 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. | |
| 30 }; | |
| 31 | |
| 32 explicit ChunkDemuxer(ChunkDemuxerClient* client); | 25 explicit ChunkDemuxer(ChunkDemuxerClient* client); |
| 33 virtual ~ChunkDemuxer(); | 26 virtual ~ChunkDemuxer(); |
| 34 | 27 |
| 35 // Demuxer implementation. | 28 // Demuxer implementation. |
| 36 virtual void Initialize(DemuxerHost* host, | 29 virtual void Initialize(DemuxerHost* host, |
| 37 const PipelineStatusCB& cb) OVERRIDE; | 30 const PipelineStatusCB& cb) OVERRIDE; |
| 38 virtual void Stop(const base::Closure& callback) OVERRIDE; | 31 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 39 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 32 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
| 40 virtual void OnAudioRendererDisabled() OVERRIDE; | 33 virtual void OnAudioRendererDisabled() OVERRIDE; |
| 41 virtual scoped_refptr<DemuxerStream> GetStream( | 34 virtual scoped_refptr<DemuxerStream> GetStream( |
| 42 DemuxerStream::Type type) OVERRIDE; | 35 DemuxerStream::Type type) OVERRIDE; |
| 43 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 36 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
| 44 virtual int GetBitrate() OVERRIDE; | 37 virtual int GetBitrate() OVERRIDE; |
| 45 virtual bool IsLocalSource() OVERRIDE; | 38 virtual bool IsLocalSource() OVERRIDE; |
| 46 virtual bool IsSeekable() OVERRIDE; | 39 virtual bool IsSeekable() OVERRIDE; |
| 47 | 40 |
| 48 // Methods used by an external object to control this demuxer. | 41 // Methods used by an external object to control this demuxer. |
| 49 void FlushData(); | 42 void FlushData(); |
| 50 | 43 |
| 51 // Registers a new |id| to use for AppendData() calls. |type| indicates | 44 // Appends media data to the stream. Returns false if this method |
| 52 // the MIME type for the data that we intend to append for this ID. | 45 // is called in an invalid state. |
| 53 // kOk is returned if the demuxer has enough resources to support another ID | 46 bool AppendData(const uint8* data, size_t length); |
| 54 // and supports the format indicated by |type|. | |
| 55 // kNotSupported is returned if |type| is not a supported format. | |
| 56 // kReachedIdLimit is returned if the demuxer cannot handle another ID right | |
| 57 // now. | |
| 58 Status AddId(const std::string& id, const std::string& type); | |
| 59 | |
| 60 // Removed an ID & associated resources that were previously added with | |
| 61 // AddId(). | |
| 62 bool RemoveId(const std::string& id); | |
| 63 | |
| 64 // Appends media data to the source buffer associated with |id|. Returns | |
| 65 // false if this method is called in an invalid state. | |
| 66 bool AppendData(const std::string& id, const uint8* data, size_t length); | |
| 67 void EndOfStream(PipelineStatus status); | 47 void EndOfStream(PipelineStatus status); |
| 68 bool HasEnded(); | 48 bool HasEnded(); |
| 69 void Shutdown(); | 49 void Shutdown(); |
| 70 | 50 |
| 71 private: | 51 private: |
| 72 enum State { | 52 enum State { |
| 73 WAITING_FOR_INIT, | 53 WAITING_FOR_INIT, |
| 74 INITIALIZING, | 54 INITIALIZING, |
| 75 INITIALIZED, | 55 INITIALIZED, |
| 76 ENDED, | 56 ENDED, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 base::TimeDelta duration_; | 88 base::TimeDelta duration_; |
| 109 | 89 |
| 110 scoped_ptr<StreamParser> stream_parser_; | 90 scoped_ptr<StreamParser> stream_parser_; |
| 111 | 91 |
| 112 // Should a Seek() call wait for more data before calling the | 92 // Should a Seek() call wait for more data before calling the |
| 113 // callback. | 93 // callback. |
| 114 bool seek_waits_for_data_; | 94 bool seek_waits_for_data_; |
| 115 | 95 |
| 116 ByteQueue byte_queue_; | 96 ByteQueue byte_queue_; |
| 117 | 97 |
| 118 // TODO(acolwell): Remove this when fixing http://crbug.com/122909 . | |
| 119 std::string source_id_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 98 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
| 122 }; | 99 }; |
| 123 | 100 |
| 124 } // namespace media | 101 } // namespace media |
| 125 | 102 |
| 126 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 103 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
| OLD | NEW |