cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / filters / ffmpeg_glue.h
blob17241b9730a7ee136488bf4604dd8c9f8d34742e
1 // Copyright (c) 2012 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.
5 // FFmpegGlue is an interface between FFmpeg and Chrome used to proxy FFmpeg's
6 // read and seek requests to Chrome's internal data structures. The glue works
7 // through the AVIO interface provided by FFmpeg.
8 //
9 // AVIO works through a special AVIOContext created through avio_alloc_context()
10 // which is attached to the AVFormatContext used for demuxing. The AVIO context
11 // is initialized with read and seek methods which FFmpeg calls when necessary.
13 // During OpenContext() FFmpegGlue will tell FFmpeg to use Chrome's AVIO context
14 // by passing NULL in for the filename parameter to avformat_open_input(). All
15 // FFmpeg operations using the configured AVFormatContext will then redirect
16 // reads and seeks through the glue.
18 // The glue in turn processes those read and seek requests using the
19 // FFmpegURLProtocol provided during construction.
21 // FFmpegGlue is also responsible for initializing FFmpeg, which is done once
22 // per process. Initialization includes: turning off log messages, registering
23 // a lock manager, and finally registering all demuxers and codecs.
25 #ifndef MEDIA_FILTERS_FFMPEG_GLUE_H_
26 #define MEDIA_FILTERS_FFMPEG_GLUE_H_
28 #include "base/basictypes.h"
29 #include "base/memory/scoped_ptr.h"
30 #include "media/base/media_export.h"
32 struct AVFormatContext;
33 struct AVIOContext;
35 namespace media {
37 class ScopedPtrAVFree;
39 class MEDIA_EXPORT FFmpegURLProtocol {
40 public:
41 // Read the given amount of bytes into data, returns the number of bytes read
42 // if successful, kReadError otherwise.
43 virtual int Read(int size, uint8* data) = 0;
45 // Returns true and the current file position for this file, false if the
46 // file position could not be retrieved.
47 virtual bool GetPosition(int64* position_out) = 0;
49 // Returns true if the file position could be set, false otherwise.
50 virtual bool SetPosition(int64 position) = 0;
52 // Returns true and the file size, false if the file size could not be
53 // retrieved.
54 virtual bool GetSize(int64* size_out) = 0;
56 // Returns false if this protocol supports random seeking.
57 virtual bool IsStreaming() = 0;
60 class MEDIA_EXPORT FFmpegGlue {
61 public:
62 static void InitializeFFmpeg();
64 // See file documentation for usage. |protocol| must outlive FFmpegGlue.
65 explicit FFmpegGlue(FFmpegURLProtocol* protocol);
66 ~FFmpegGlue();
68 // Opens an AVFormatContext specially prepared to process reads and seeks
69 // through the FFmpegURLProtocol provided during construction.
70 bool OpenContext();
71 AVFormatContext* format_context() { return format_context_; }
73 private:
74 bool open_called_;
75 AVFormatContext* format_context_;
76 scoped_ptr_malloc<AVIOContext, ScopedPtrAVFree> avio_context_;
78 DISALLOW_COPY_AND_ASSIGN(FFmpegGlue);
81 } // namespace media
83 #endif // MEDIA_FILTERS_FFMPEG_GLUE_H_