Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: media/filters/ffmpeg_demuxer.h

Issue 39295: Checking in media::FFmpegDemuxer and tests. (Closed)
Patch Set: Fixes Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/build/media_unittests.vcproj ('k') | media/filters/ffmpeg_demuxer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
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
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
9 // can be used to create and initialize the corresponding FFmpeg decoder.
10 //
11 // FFmpegDemuxer sets the duration of pipeline during initialization by using
12 // the duration of the longest audio/video stream.
13 //
14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media
15 // files with very large drift between audio/video streams may result in
16 // excessive memory consumption.
17
18 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_
19 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_
20
21 #include <deque>
22 #include <vector>
23
24 #include "base/lock.h"
25 #include "media/base/buffers.h"
26 #include "media/base/factory.h"
27 #include "media/base/filters.h"
28 #include "media/base/media_format.h"
29
30 // FFmpeg forward declarations.
31 struct AVCodecContext;
32 struct AVBitStreamFilterContext;
33 struct AVFormatContext;
34 struct AVPacket;
35 struct AVStream;
36 enum CodecID;
37
38 namespace media {
39
40 class FFmpegDemuxer;
41
42 class FFmpegDemuxerStream : public DemuxerStream {
43 public:
44 // Maintains a reference to |demuxer| and initializes itself using information
45 // inside |stream|.
46 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, const AVStream& stream);
47
48 virtual ~FFmpegDemuxerStream();
49
50 // Returns true is this stream has pending reads, false otherwise.
51 bool HasPendingReads();
52
53 // Enqueues and takes ownership over the given AVPacket.
54 void EnqueuePacket(AVPacket* packet);
55
56 // Returns the duration of this stream.
57 base::TimeDelta duration() { return duration_; }
58
59 // DemuxerStream implementation.
60 virtual const MediaFormat* GetMediaFormat();
61 virtual void Read(Assignable<Buffer>* buffer);
62
63 private:
64 // Returns true if there are still pending reads.
65 bool FulfillPendingReads();
66
67 FFmpegDemuxer* demuxer_;
68 MediaFormat media_format_;
69 base::TimeDelta time_base_;
70 base::TimeDelta duration_;
71 Lock lock_;
72
73 typedef std::deque< scoped_refptr<Buffer> > InputQueue;
74 InputQueue input_queue_;
75
76 typedef std::deque< scoped_refptr< Assignable<Buffer> > > OutputQueue;
77 OutputQueue output_queue_;
78
79 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream);
80 };
81
82 class FFmpegDemuxer : public Demuxer {
83 public:
84 // FilterFactory provider.
85 static FilterFactory* CreateFilterFactory() {
86 return new FilterFactoryImpl0<FFmpegDemuxer>();
87 }
88
89 // Called by FFmpegDemuxerStreams to schedule a Demux() task.
90 void ScheduleDemux();
91
92 // MediaFilter implementation.
93 virtual void Stop();
94
95 // Demuxer implementation.
96 virtual bool Initialize(DataSource* data_source);
97 virtual size_t GetNumberOfStreams();
98 virtual DemuxerStream* GetStream(int stream_id);
99
100 private:
101 // Only allow a factory to create this class.
102 friend class FilterFactoryImpl0<FFmpegDemuxer>;
103 FFmpegDemuxer();
104 virtual ~FFmpegDemuxer();
105
106 // Demuxing task scheduled by streams.
107 void Demux();
108
109 // Returns true if any of the streams have pending reads.
110 bool StreamsHavePendingReads();
111
112 // Flag to prevent multiple Demux() tasks from being scheduled.
113 bool demuxing_;
114
115 // FFmpeg context handle.
116 AVFormatContext* format_context_;
117
118 // Vector of streams.
119 typedef std::vector<FFmpegDemuxerStream*> StreamVector;
120 StreamVector streams_;
121
122 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
123 };
124
125 } // namespace media
126
127 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW
« no previous file with comments | « media/build/media_unittests.vcproj ('k') | media/filters/ffmpeg_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698