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 #include "media/filters/ffmpeg_glue.h" | 5 #include "media/filters/ffmpeg_glue.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "media/base/filters.h" | 9 #include "media/base/filters.h" |
10 #include "media/ffmpeg/ffmpeg_common.h" | 10 #include "media/ffmpeg/ffmpeg_common.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 static FFmpegURLProtocol* ToProtocol(void* data) { | 14 static FFmpegURLProtocol* ToProtocol(void* data) { |
15 return reinterpret_cast<FFmpegURLProtocol*>(data); | 15 return reinterpret_cast<FFmpegURLProtocol*>(data); |
16 } | 16 } |
17 | 17 |
18 // FFmpeg protocol interface. | 18 // FFmpeg protocol interface. |
19 static int OpenContext(URLContext* h, const char* filename, int flags) { | 19 static int OpenContext(URLContext* h, const char* filename, int flags) { |
20 FFmpegURLProtocol* protocol; | 20 FFmpegURLProtocol* protocol; |
21 FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol); | 21 FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol); |
22 if (!protocol) | 22 if (!protocol) |
23 return AVERROR(EIO); | 23 return AVERROR(EIO); |
24 | 24 |
25 h->priv_data = protocol; | 25 h->priv_data = protocol; |
26 h->flags = URL_RDONLY; | 26 h->flags = AVIO_FLAG_READ; |
27 h->is_streamed = protocol->IsStreaming(); | 27 h->is_streamed = protocol->IsStreaming(); |
28 return 0; | 28 return 0; |
29 } | 29 } |
30 | 30 |
31 static int Open2Context(URLContext* h, const char* filename, int flags, | |
32 AVDictionary **options) { | |
33 // TODO(dalecurtis): This is probably not right... | |
34 return OpenContext(h, filename, flags); | |
35 } | |
36 | |
31 static int ReadContext(URLContext* h, unsigned char* buf, int size) { | 37 static int ReadContext(URLContext* h, unsigned char* buf, int size) { |
32 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 38 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
33 int result = protocol->Read(size, buf); | 39 int result = protocol->Read(size, buf); |
34 if (result < 0) | 40 if (result < 0) |
35 result = AVERROR(EIO); | 41 result = AVERROR(EIO); |
36 return result; | 42 return result; |
37 } | 43 } |
38 | 44 |
39 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) | 45 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) |
40 static int WriteContext(URLContext* h, const unsigned char* buf, int size) { | 46 static int WriteContext(URLContext* h, const unsigned char* buf, int size) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 return 1; | 117 return 1; |
112 } | 118 } |
113 | 119 |
114 // Use the HTTP protocol to avoid any file path separator issues. | 120 // Use the HTTP protocol to avoid any file path separator issues. |
115 static const char kProtocol[] = "http"; | 121 static const char kProtocol[] = "http"; |
116 | 122 |
117 // Fill out our FFmpeg protocol definition. | 123 // Fill out our FFmpeg protocol definition. |
118 static URLProtocol kFFmpegURLProtocol = { | 124 static URLProtocol kFFmpegURLProtocol = { |
119 kProtocol, | 125 kProtocol, |
120 &OpenContext, | 126 &OpenContext, |
127 &Open2Context, | |
scherkus (not reviewing)
2012/02/06 21:13:49
ditto for NULL here
DaleCurtis
2012/02/07 19:09:13
Done.
| |
121 &ReadContext, | 128 &ReadContext, |
122 &WriteContext, | 129 &WriteContext, |
123 &SeekContext, | 130 &SeekContext, |
124 &CloseContext, | 131 &CloseContext, |
125 }; | 132 }; |
126 | 133 |
127 FFmpegGlue::FFmpegGlue() { | 134 FFmpegGlue::FFmpegGlue() { |
128 // Before doing anything disable logging as it interferes with layout tests. | 135 // Before doing anything disable logging as it interferes with layout tests. |
129 av_log_set_level(AV_LOG_QUIET); | 136 av_log_set_level(AV_LOG_QUIET); |
130 | 137 |
131 // Register our protocol glue code with FFmpeg. | 138 // Register our protocol glue code with FFmpeg. |
132 avcodec_init(); | 139 ffurl_register_protocol(&kFFmpegURLProtocol, sizeof(kFFmpegURLProtocol)); |
133 av_register_protocol2(&kFFmpegURLProtocol, sizeof(kFFmpegURLProtocol)); | |
134 av_lockmgr_register(&LockManagerOperation); | 140 av_lockmgr_register(&LockManagerOperation); |
135 | 141 |
136 // Now register the rest of FFmpeg. | 142 // Now register the rest of FFmpeg. |
137 av_register_all(); | 143 av_register_all(); |
138 } | 144 } |
139 | 145 |
140 FFmpegGlue::~FFmpegGlue() { | 146 FFmpegGlue::~FFmpegGlue() { |
141 av_lockmgr_register(NULL); | 147 av_lockmgr_register(NULL); |
142 } | 148 } |
143 | 149 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 } | 190 } |
185 | 191 |
186 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 192 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
187 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 193 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
188 // This also has the nice property that adding the same FFmpegURLProtocol | 194 // This also has the nice property that adding the same FFmpegURLProtocol |
189 // reference will not generate duplicate entries. | 195 // reference will not generate duplicate entries. |
190 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 196 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
191 } | 197 } |
192 | 198 |
193 } // namespace media | 199 } // namespace media |
OLD | NEW |