OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
24 | 24 |
25 #include <deque> | 25 #include <deque> |
26 #include <vector> | 26 #include <vector> |
27 | 27 |
28 #include "base/callback.h" | 28 #include "base/callback.h" |
29 #include "base/gtest_prod_util.h" | 29 #include "base/gtest_prod_util.h" |
30 #include "base/synchronization/waitable_event.h" | 30 #include "base/synchronization/waitable_event.h" |
| 31 #include "media/base/audio_decoder_config.h" |
31 #include "media/base/buffers.h" | 32 #include "media/base/buffers.h" |
32 #include "media/base/demuxer.h" | 33 #include "media/base/demuxer.h" |
33 #include "media/base/pipeline.h" | 34 #include "media/base/pipeline.h" |
34 #include "media/filters/ffmpeg_glue.h" | 35 #include "media/filters/ffmpeg_glue.h" |
35 | 36 |
36 // FFmpeg forward declarations. | 37 // FFmpeg forward declarations. |
37 struct AVFormatContext; | 38 struct AVFormatContext; |
38 struct AVPacket; | 39 struct AVPacket; |
39 struct AVRational; | 40 struct AVRational; |
40 | 41 |
41 namespace media { | 42 namespace media { |
42 | 43 |
43 class BitstreamConverter; | 44 class BitstreamConverter; |
44 class FFmpegDemuxer; | 45 class FFmpegDemuxer; |
45 | 46 |
46 // Forward declaration for scoped_ptr_malloc. | 47 // Forward declaration for scoped_ptr_malloc. |
47 class ScopedPtrAVFree; | 48 class ScopedPtrAVFree; |
48 | 49 |
49 class FFmpegDemuxerStream : public DemuxerStream { | 50 class FFmpegDemuxerStream : public DemuxerStream { |
50 public: | 51 public: |
51 // Keeps a copy of |demuxer| and initializes itself using information | 52 // Keeps a copy of |demuxer| and initializes itself using information |
52 // inside |stream|. Both parameters must outlive |this|. | 53 // inside |stream|. Both parameters must outlive |this|. |
53 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); | 54 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); |
54 | 55 |
55 // Returns true is this stream has pending reads, false otherwise. | 56 // Returns true is this stream has pending reads, false otherwise. |
56 // | 57 // |
57 // Safe to call on any thread. | 58 // Safe to call on any thread. |
58 virtual bool HasPendingReads(); | 59 bool HasPendingReads(); |
59 | 60 |
60 // Enqueues and takes ownership over the given AVPacket. | 61 // Enqueues and takes ownership over the given AVPacket. |
61 virtual void EnqueuePacket(AVPacket* packet); | 62 void EnqueuePacket(AVPacket* packet); |
62 | 63 |
63 // Signals to empty the buffer queue and mark next packet as discontinuous. | 64 // Signals to empty the buffer queue and mark next packet as discontinuous. |
64 virtual void FlushBuffers(); | 65 void FlushBuffers(); |
65 | 66 |
66 // Empties the queues and ignores any additional calls to Read(). | 67 // Empties the queues and ignores any additional calls to Read(). |
67 virtual void Stop(); | 68 void Stop(); |
68 | 69 |
69 // Returns the duration of this stream. | 70 // Returns the duration of this stream. |
70 virtual base::TimeDelta duration(); | 71 base::TimeDelta duration(); |
71 | 72 |
72 // DemuxerStream implementation. | 73 // DemuxerStream implementation. |
73 virtual Type type(); | 74 virtual Type type() OVERRIDE; |
74 | 75 |
75 // If |buffer_queue_| is not empty will execute on caller's thread, otherwise | 76 // If |buffer_queue_| is not empty will execute on caller's thread, otherwise |
76 // will post ReadTask to execute on demuxer's thread. Read will acquire | 77 // will post ReadTask to execute on demuxer's thread. Read will acquire |
77 // |lock_| for the life of the function so that means |read_callback| must | 78 // |lock_| for the life of the function so that means |read_callback| must |
78 // not make calls into FFmpegDemuxerStream directly or that may cause a | 79 // not make calls into FFmpegDemuxerStream directly or that may cause a |
79 // deadlock. |read_callback| should execute as quickly as possible because | 80 // deadlock. |read_callback| should execute as quickly as possible because |
80 // |lock_| is held throughout the life of the callback. | 81 // |lock_| is held throughout the life of the callback. |
81 virtual void Read(const ReadCallback& read_callback); | 82 virtual void Read(const ReadCallback& read_callback) OVERRIDE; |
82 // Bitstream converter to convert input packet. | 83 virtual void EnableBitstreamConverter() OVERRIDE; |
83 virtual void EnableBitstreamConverter(); | 84 virtual AVStream* GetAVStream() OVERRIDE; |
84 virtual AVStream* GetAVStream(); | 85 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
85 | 86 |
86 private: | 87 private: |
87 virtual ~FFmpegDemuxerStream(); | 88 virtual ~FFmpegDemuxerStream(); |
88 | 89 |
89 // Carries out enqueuing a pending read on the demuxer thread. | 90 // Carries out enqueuing a pending read on the demuxer thread. |
90 void ReadTask(const ReadCallback& read_callback); | 91 void ReadTask(const ReadCallback& read_callback); |
91 | 92 |
92 // Attempts to fulfill a single pending read by dequeueing a buffer and read | 93 // Attempts to fulfill a single pending read by dequeueing a buffer and read |
93 // callback pair and executing the callback. The calling function must | 94 // callback pair and executing the callback. The calling function must |
94 // acquire |lock_| before calling this function. | 95 // acquire |lock_| before calling this function. |
95 void FulfillPendingRead(); | 96 void FulfillPendingRead(); |
96 | 97 |
97 // Converts an FFmpeg stream timestamp into a base::TimeDelta. | 98 // Converts an FFmpeg stream timestamp into a base::TimeDelta. |
98 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 99 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
99 int64 timestamp); | 100 int64 timestamp); |
100 | 101 |
101 FFmpegDemuxer* demuxer_; | 102 FFmpegDemuxer* demuxer_; |
102 AVStream* stream_; | 103 AVStream* stream_; |
| 104 AudioDecoderConfig audio_config_; |
103 Type type_; | 105 Type type_; |
104 base::TimeDelta duration_; | 106 base::TimeDelta duration_; |
105 bool discontinuous_; | 107 bool discontinuous_; |
106 bool stopped_; | 108 bool stopped_; |
107 | 109 |
108 typedef std::deque<scoped_refptr<Buffer> > BufferQueue; | 110 typedef std::deque<scoped_refptr<Buffer> > BufferQueue; |
109 BufferQueue buffer_queue_; | 111 BufferQueue buffer_queue_; |
110 | 112 |
111 typedef std::deque<ReadCallback> ReadQueue; | 113 typedef std::deque<ReadCallback> ReadQueue; |
112 ReadQueue read_queue_; | 114 ReadQueue read_queue_; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // starting clock value to match the timestamps in the media file. Default | 258 // starting clock value to match the timestamps in the media file. Default |
257 // is 0. | 259 // is 0. |
258 base::TimeDelta start_time_; | 260 base::TimeDelta start_time_; |
259 | 261 |
260 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 262 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
261 }; | 263 }; |
262 | 264 |
263 } // namespace media | 265 } // namespace media |
264 | 266 |
265 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 267 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |