Chromium Code Reviews| 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 // FFmpegGlue is an adapter for FFmpeg's URLProtocol interface that allows us to | 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 | 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 | 7 // avformat_open_input function, which analyzes the filename given to it and |
|
scherkus (not reviewing)
2012/02/06 21:13:49
nit: mind annotating the function calls in comment
DaleCurtis
2012/02/07 19:09:13
Done.
| |
| 8 // automatically initializes the appropriate URLProtocol. | 8 // automatically initializes the appropriate URLProtocol. |
| 9 // | 9 // |
| 10 // Since the DataSource is already open by time we call av_open_input_file, we | 10 // Since the DataSource is already open by time we call avformat_open_input, we |
| 11 // need a way for av_open_input_file to find the correct DataSource instance. | 11 // need a way for avformat_open_input to find the correct DataSource instance. |
| 12 // The solution is to maintain a map of "filenames" to DataSource instances, | 12 // The solution is to maintain a map of "filenames" to DataSource instances, |
| 13 // where filenames are actually just a unique identifier. For simplicity, | 13 // where filenames are actually just a unique identifier. For simplicity, |
| 14 // FFmpegGlue is registered as an HTTP handler and generates filenames based on | 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 | 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 | 16 // may be multiple FFmpegDemuxers active at one time, FFmpegGlue is a |
| 17 // thread-safe singleton. | 17 // thread-safe singleton. |
| 18 // | 18 // |
| 19 // Usage: FFmpegDemuxer adds the DataSource to FFmpegGlue's map and is given a | 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 | 20 // filename to pass to avformat_open_input. FFmpegDemuxer calls |
| 21 // av_open_input_file with the filename, which results in FFmpegGlue returning | 21 // avformat_open_input with the filename, which results in FFmpegGlue returning |
| 22 // the DataSource as a URLProtocol instance to FFmpeg. Since FFmpegGlue is only | 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 | 23 // needed for opening files, when avformat_open_input returns FFmpegDemuxer |
| 24 // removes the DataSource from FFmpegGlue's map. | 24 // removes the DataSource from FFmpegGlue's map. |
| 25 | 25 |
| 26 #ifndef MEDIA_FILTERS_FFMPEG_GLUE_H_ | 26 #ifndef MEDIA_FILTERS_FFMPEG_GLUE_H_ |
| 27 #define MEDIA_FILTERS_FFMPEG_GLUE_H_ | 27 #define MEDIA_FILTERS_FFMPEG_GLUE_H_ |
| 28 | 28 |
| 29 #include <map> | 29 #include <map> |
| 30 #include <string> | 30 #include <string> |
| 31 | 31 |
| 32 #include "base/memory/singleton.h" | 32 #include "base/memory/singleton.h" |
| 33 #include "base/synchronization/lock.h" | 33 #include "base/synchronization/lock.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 void GetProtocol(const std::string& key, | 83 void GetProtocol(const std::string& key, |
| 84 FFmpegURLProtocol** protocol); | 84 FFmpegURLProtocol** protocol); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 // Only allow Singleton to create and delete FFmpegGlue. | 87 // Only allow Singleton to create and delete FFmpegGlue. |
| 88 friend struct DefaultSingletonTraits<FFmpegGlue>; | 88 friend struct DefaultSingletonTraits<FFmpegGlue>; |
| 89 FFmpegGlue(); | 89 FFmpegGlue(); |
| 90 virtual ~FFmpegGlue(); | 90 virtual ~FFmpegGlue(); |
| 91 | 91 |
| 92 // Returns the unique key for this data source, which can be passed to | 92 // Returns the unique key for this data source, which can be passed to |
| 93 // av_open_input_file as the filename. | 93 // avformat_open_input as the filename. |
| 94 std::string GetProtocolKey(FFmpegURLProtocol* protocol); | 94 std::string GetProtocolKey(FFmpegURLProtocol* protocol); |
| 95 | 95 |
| 96 // Mutual exclusion while adding/removing items from the map. | 96 // Mutual exclusion while adding/removing items from the map. |
| 97 base::Lock lock_; | 97 base::Lock lock_; |
| 98 | 98 |
| 99 // Map between keys and FFmpegProtocol references. | 99 // Map between keys and FFmpegProtocol references. |
| 100 typedef std::map<std::string, FFmpegURLProtocol*> ProtocolMap; | 100 typedef std::map<std::string, FFmpegURLProtocol*> ProtocolMap; |
| 101 ProtocolMap protocols_; | 101 ProtocolMap protocols_; |
| 102 | 102 |
| 103 friend class FFmpegGlueTest; | 103 friend class FFmpegGlueTest; |
| 104 static URLProtocol* url_protocol(); | 104 static URLProtocol* url_protocol(); |
| 105 | 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(FFmpegGlue); | 106 DISALLOW_COPY_AND_ASSIGN(FFmpegGlue); |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 } // namespace media | 109 } // namespace media |
| 110 | 110 |
| 111 #endif // MEDIA_FILTERS_FFMPEG_GLUE_H_ | 111 #endif // MEDIA_FILTERS_FFMPEG_GLUE_H_ |
| OLD | NEW |