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

Unified Diff: media/filters/ffmpeg_glue.h

Issue 10912080: Switch to AVIO instead of a custom FFmpeg URLProtocol handler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/ffmpeg_demuxer_unittest.cc ('k') | media/filters/ffmpeg_glue.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_glue.h
diff --git a/media/filters/ffmpeg_glue.h b/media/filters/ffmpeg_glue.h
index c5aa15c2ad8220dc0e3dfd2a3fcfda9b3ae70edc..17241b9730a7ee136488bf4604dd8c9f8d34742e 100644
--- a/media/filters/ffmpeg_glue.h
+++ b/media/filters/ffmpeg_glue.h
@@ -2,48 +2,45 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// FFmpegGlue is an adapter for FFmpeg's URLProtocol interface that allows us to
-// use a DataSource implementation with FFmpeg. For convenience we use FFmpeg's
-// avformat_open_input() function, which analyzes the filename given to it and
-// automatically initializes the appropriate URLProtocol.
+// FFmpegGlue is an interface between FFmpeg and Chrome used to proxy FFmpeg's
+// read and seek requests to Chrome's internal data structures. The glue works
+// through the AVIO interface provided by FFmpeg.
//
-// Since the DataSource is already open by time we call avformat_open_input(),
-// we need a way for avformat_open_input() to find the correct DataSource
-// instance. The solution is to maintain a map of "filenames" to DataSource
-// instances, where filenames are actually just a unique identifier. For
-// simplicity, FFmpegGlue is registered as an HTTP handler and generates
-// filenames based on the memory address of the DataSource, i.e.,
-// http://0xc0bf4870. Since there may be multiple FFmpegDemuxers active at one
-// time, FFmpegGlue is a thread-safe singleton.
+// AVIO works through a special AVIOContext created through avio_alloc_context()
+// which is attached to the AVFormatContext used for demuxing. The AVIO context
+// is initialized with read and seek methods which FFmpeg calls when necessary.
//
-// Usage: FFmpegDemuxer adds the DataSource to FFmpegGlue's map and is given a
-// filename to pass to avformat_open_input(). FFmpegDemuxer calls
-// avformat_open_input() with the filename, which results in FFmpegGlue
-// returning the DataSource as a URLProtocol instance to FFmpeg. Since
-// FFmpegGlue is only needed for opening files, when avformat_open_input()
-// returns FFmpegDemuxer removes the DataSource from FFmpegGlue's map.
+// During OpenContext() FFmpegGlue will tell FFmpeg to use Chrome's AVIO context
+// by passing NULL in for the filename parameter to avformat_open_input(). All
+// FFmpeg operations using the configured AVFormatContext will then redirect
+// reads and seeks through the glue.
+//
+// The glue in turn processes those read and seek requests using the
+// FFmpegURLProtocol provided during construction.
+//
+// FFmpegGlue is also responsible for initializing FFmpeg, which is done once
+// per process. Initialization includes: turning off log messages, registering
+// a lock manager, and finally registering all demuxers and codecs.
#ifndef MEDIA_FILTERS_FFMPEG_GLUE_H_
#define MEDIA_FILTERS_FFMPEG_GLUE_H_
-#include <map>
-#include <string>
-
-#include "base/memory/singleton.h"
-#include "base/synchronization/lock.h"
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "media/base/media_export.h"
-struct URLProtocol;
+struct AVFormatContext;
+struct AVIOContext;
namespace media {
+class ScopedPtrAVFree;
+
class MEDIA_EXPORT FFmpegURLProtocol {
public:
- FFmpegURLProtocol() {}
-
// Read the given amount of bytes into data, returns the number of bytes read
// if successful, kReadError otherwise.
- virtual size_t Read(size_t size, uint8* data) = 0;
+ virtual int Read(int size, uint8* data) = 0;
// Returns true and the current file position for this file, false if the
// file position could not be retrieved.
@@ -58,51 +55,25 @@ class MEDIA_EXPORT FFmpegURLProtocol {
// Returns false if this protocol supports random seeking.
virtual bool IsStreaming() = 0;
-
- protected:
- virtual ~FFmpegURLProtocol() {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(FFmpegURLProtocol);
};
class MEDIA_EXPORT FFmpegGlue {
public:
- // Returns the singleton instance.
- static FFmpegGlue* GetInstance();
-
- // Adds a FFmpegProtocol to the FFmpeg glue layer and returns a unique string
- // that can be passed to FFmpeg to identify the data source.
- std::string AddProtocol(FFmpegURLProtocol* protocol);
+ static void InitializeFFmpeg();
- // Removes a FFmpegProtocol from the FFmpeg glue layer. Using strings from
- // previously added FFmpegProtocols will no longer work.
- void RemoveProtocol(FFmpegURLProtocol* protocol);
+ // See file documentation for usage. |protocol| must outlive FFmpegGlue.
+ explicit FFmpegGlue(FFmpegURLProtocol* protocol);
+ ~FFmpegGlue();
- // Assigns the FFmpegProtocol identified with by the given key to
- // |protocol|, or assigns NULL if no such FFmpegProtocol could be found.
- void GetProtocol(const std::string& key,
- FFmpegURLProtocol** protocol);
+ // Opens an AVFormatContext specially prepared to process reads and seeks
+ // through the FFmpegURLProtocol provided during construction.
+ bool OpenContext();
+ AVFormatContext* format_context() { return format_context_; }
private:
- // Only allow Singleton to create and delete FFmpegGlue.
- friend struct DefaultSingletonTraits<FFmpegGlue>;
- FFmpegGlue();
- virtual ~FFmpegGlue();
-
- // Returns the unique key for this data source, which can be passed to
- // avformat_open_input() as the filename.
- std::string GetProtocolKey(FFmpegURLProtocol* protocol);
-
- // Mutual exclusion while adding/removing items from the map.
- base::Lock lock_;
-
- // Map between keys and FFmpegProtocol references.
- typedef std::map<std::string, FFmpegURLProtocol*> ProtocolMap;
- ProtocolMap protocols_;
-
- friend class FFmpegGlueTest;
- static URLProtocol* url_protocol();
+ bool open_called_;
+ AVFormatContext* format_context_;
+ scoped_ptr_malloc<AVIOContext, ScopedPtrAVFree> avio_context_;
DISALLOW_COPY_AND_ASSIGN(FFmpegGlue);
};
« no previous file with comments | « media/filters/ffmpeg_demuxer_unittest.cc ('k') | media/filters/ffmpeg_glue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698