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

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

Issue 28165: Checking in media::FFmpegGlue and some common FFmpeg code. (Closed)
Patch Set: mime type stuff 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/filters/ffmpeg_common.cc ('k') | media/filters/ffmpeg_glue.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 // FFmpegGlue is an adapter for FFmpeg's URLProtocol interface that allows us to
6 // use a DataSource implementation with FFmpeg. For convenience we use FFmpeg's
7 // av_open_input_file function, which analyzes the filename given to it and
8 // automatically initializes the appropriate URLProtocol.
9 //
10 // Since the DataSource is already open by time we call av_open_input_file, we
11 // need a way for av_open_input_file to find the correct DataSource instance.
12 // The solution is to maintain a map of "filenames" to DataSource instances,
13 // where filenames are actually just a unique identifier. For simplicity,
14 // FFmpegGlue is registered as an HTTP handler and generates filenames based on
15 // the memory address of the DataSource, i.e., http://0xc0bf4870. Since there
16 // may be multiple FFmpegDemuxers active at one time, FFmpegGlue is a
17 // thread-safe singleton.
18 //
19 // Usage: FFmpegDemuxer adds the DataSource to FFmpegGlue's map and is given a
20 // filename to pass to av_open_input_file. FFmpegDemuxer calls
21 // av_open_input_file with the filename, which results in FFmpegGlue returning
22 // the DataSource as a URLProtocol instance to FFmpeg. Since FFmpegGlue is only
23 // needed for opening files, when av_open_input_file returns FFmpegDemuxer
24 // removes the DataSource from FFmpegGlue's map.
25
26 #ifndef MEDIA_FILTERS_FFMPEG_GLUE_H_
27 #define MEDIA_FILTERS_FFMPEG_GLUE_H_
28
29 #include <map>
30 #include <string>
31
32 #include "base/lock.h"
33 #include "base/singleton.h"
34
35 // FFmpeg forward declarations.
36 struct URLContext;
37 typedef int64 offset_t;
38
39 namespace media {
40
41 class DataSource;
42
43 class FFmpegGlue : public Singleton<FFmpegGlue> {
44 public:
45 // Adds a DataSource to the FFmpeg glue layer and returns a unique string that
46 // can be passed to FFmpeg to identify the data source.
47 std::string AddDataSource(DataSource* data_source);
48
49 // Removes a DataSource from the FFmpeg glue layer. Using strings from
50 // previously added DataSources will no longer work.
51 void RemoveDataSource(DataSource* data_source);
52
53 // Assigns the DataSource identified with by the given key to |data_source|,
54 // or assigns NULL if no such DataSource could be found.
55 void GetDataSource(const std::string& key,
56 scoped_refptr<DataSource>* data_source);
57
58 private:
59 // Only allow Singleton to create and delete FFmpegGlue.
60 friend struct DefaultSingletonTraits<FFmpegGlue>;
61 FFmpegGlue();
62 virtual ~FFmpegGlue();
63
64 // Returns the unique key for this data source, which can be passed to
65 // av_open_input_file as the filename.
66 std::string GetDataSourceKey(DataSource* data_source);
67
68 // Mutual exclusion while adding/removing items from the map.
69 Lock lock_;
70
71 // Map between keys and DataSource references.
72 typedef std::map< std::string, scoped_refptr<DataSource> > DataSourceMap;
73 DataSourceMap data_sources_;
74
75 DISALLOW_COPY_AND_ASSIGN(FFmpegGlue);
76 };
77
78 } // namespace media
79
80 #endif // MEDIA_FILTERS_FFMPEG_GLUE_H_
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_common.cc ('k') | media/filters/ffmpeg_glue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698