OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Implements the Demuxer interface using FFmpeg's libavformat. At this time | 5 // Implements the Demuxer interface using FFmpeg's libavformat. At this time |
6 // will support demuxing any audio/video format thrown at it. The streams | 6 // will support demuxing any audio/video format thrown at it. The streams |
7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer | 7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer |
8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs | 8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs |
9 // can be used to create and initialize the corresponding FFmpeg decoder. | 9 // can be used to create and initialize the corresponding FFmpeg decoder. |
10 // | 10 // |
(...skipping 25 matching lines...) Expand all Loading... |
36 enum CodecID; | 36 enum CodecID; |
37 | 37 |
38 namespace media { | 38 namespace media { |
39 | 39 |
40 class FFmpegDemuxer; | 40 class FFmpegDemuxer; |
41 | 41 |
42 class FFmpegDemuxerStream : public DemuxerStream { | 42 class FFmpegDemuxerStream : public DemuxerStream { |
43 public: | 43 public: |
44 // Maintains a reference to |demuxer| and initializes itself using information | 44 // Maintains a reference to |demuxer| and initializes itself using information |
45 // inside |stream|. | 45 // inside |stream|. |
46 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, const AVStream& stream); | 46 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); |
47 | 47 |
48 virtual ~FFmpegDemuxerStream(); | 48 virtual ~FFmpegDemuxerStream(); |
49 | 49 |
50 // Returns true is this stream has pending reads, false otherwise. | 50 // Returns true is this stream has pending reads, false otherwise. |
51 bool HasPendingReads(); | 51 bool HasPendingReads(); |
52 | 52 |
53 // Enqueues and takes ownership over the given AVPacket. | 53 // Enqueues and takes ownership over the given AVPacket. |
54 void EnqueuePacket(AVPacket* packet); | 54 void EnqueuePacket(AVPacket* packet); |
55 | 55 |
56 // Returns the duration of this stream. | 56 // Returns the duration of this stream. |
57 base::TimeDelta duration() { return duration_; } | 57 base::TimeDelta duration() { return duration_; } |
58 | 58 |
59 // DemuxerStream implementation. | 59 // DemuxerStream implementation. |
60 virtual const MediaFormat* GetMediaFormat(); | 60 virtual const MediaFormat* GetMediaFormat(); |
61 virtual void Read(Assignable<Buffer>* buffer); | 61 virtual void Read(Assignable<Buffer>* buffer); |
62 | 62 |
| 63 AVStream* av_stream() { |
| 64 return av_stream_; |
| 65 } |
| 66 |
| 67 static const char* interface_id(); |
| 68 |
| 69 protected: |
| 70 virtual void* QueryInterface(const char* interface_id); |
| 71 |
63 private: | 72 private: |
64 // Returns true if there are still pending reads. | 73 // Returns true if there are still pending reads. |
65 bool FulfillPendingReads(); | 74 bool FulfillPendingReads(); |
66 | 75 |
67 FFmpegDemuxer* demuxer_; | 76 FFmpegDemuxer* demuxer_; |
| 77 AVStream* av_stream_; |
68 MediaFormat media_format_; | 78 MediaFormat media_format_; |
69 base::TimeDelta time_base_; | 79 base::TimeDelta time_base_; |
70 base::TimeDelta duration_; | 80 base::TimeDelta duration_; |
71 Lock lock_; | 81 Lock lock_; |
72 | 82 |
73 typedef std::deque< scoped_refptr<Buffer> > InputQueue; | 83 typedef std::deque< scoped_refptr<Buffer> > InputQueue; |
74 InputQueue input_queue_; | 84 InputQueue input_queue_; |
75 | 85 |
76 typedef std::deque< scoped_refptr< Assignable<Buffer> > > OutputQueue; | 86 typedef std::deque< scoped_refptr< Assignable<Buffer> > > OutputQueue; |
77 OutputQueue output_queue_; | 87 OutputQueue output_queue_; |
(...skipping 10 matching lines...) Expand all Loading... |
88 | 98 |
89 // Called by FFmpegDemuxerStreams to schedule a Demux() task. | 99 // Called by FFmpegDemuxerStreams to schedule a Demux() task. |
90 void ScheduleDemux(); | 100 void ScheduleDemux(); |
91 | 101 |
92 // MediaFilter implementation. | 102 // MediaFilter implementation. |
93 virtual void Stop(); | 103 virtual void Stop(); |
94 | 104 |
95 // Demuxer implementation. | 105 // Demuxer implementation. |
96 virtual bool Initialize(DataSource* data_source); | 106 virtual bool Initialize(DataSource* data_source); |
97 virtual size_t GetNumberOfStreams(); | 107 virtual size_t GetNumberOfStreams(); |
98 virtual DemuxerStream* GetStream(int stream_id); | 108 virtual scoped_refptr<DemuxerStream> GetStream(int stream_id); |
99 | 109 |
100 private: | 110 private: |
101 // Only allow a factory to create this class. | 111 // Only allow a factory to create this class. |
102 friend class FilterFactoryImpl0<FFmpegDemuxer>; | 112 friend class FilterFactoryImpl0<FFmpegDemuxer>; |
103 FFmpegDemuxer(); | 113 FFmpegDemuxer(); |
104 virtual ~FFmpegDemuxer(); | 114 virtual ~FFmpegDemuxer(); |
105 | 115 |
106 // Demuxing task scheduled by streams. | 116 // Demuxing task scheduled by streams. |
107 void Demux(); | 117 void Demux(); |
108 | 118 |
109 // Returns true if any of the streams have pending reads. | 119 // Returns true if any of the streams have pending reads. |
110 bool StreamsHavePendingReads(); | 120 bool StreamsHavePendingReads(); |
111 | 121 |
112 // Flag to prevent multiple Demux() tasks from being scheduled. | 122 // Flag to prevent multiple Demux() tasks from being scheduled. |
113 bool demuxing_; | 123 bool demuxing_; |
114 | 124 |
115 // FFmpeg context handle. | 125 // FFmpeg context handle. |
116 AVFormatContext* format_context_; | 126 AVFormatContext* format_context_; |
117 | 127 |
118 // Vector of streams. | 128 // Vector of streams. |
119 typedef std::vector<FFmpegDemuxerStream*> StreamVector; | 129 typedef std::vector< scoped_refptr<FFmpegDemuxerStream> > StreamVector; |
120 StreamVector streams_; | 130 StreamVector streams_; |
121 | 131 |
122 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 132 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
123 }; | 133 }; |
124 | 134 |
125 } // namespace media | 135 } // namespace media |
126 | 136 |
127 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 137 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |