OLD | NEW |
1 // Copyright (c) 2010 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" |
| 6 |
5 #include "base/string_util.h" | 7 #include "base/string_util.h" |
6 #include "media/base/filters.h" | 8 #include "media/base/filters.h" |
7 #include "media/ffmpeg/ffmpeg_common.h" | 9 #include "media/ffmpeg/ffmpeg_common.h" |
8 #include "media/filters/ffmpeg_glue.h" | |
9 | 10 |
10 namespace { | 11 namespace media { |
11 | 12 |
12 media::FFmpegURLProtocol* ToProtocol(void* data) { | 13 static FFmpegURLProtocol* ToProtocol(void* data) { |
13 return reinterpret_cast<media::FFmpegURLProtocol*>(data); | 14 return reinterpret_cast<FFmpegURLProtocol*>(data); |
14 } | 15 } |
15 | 16 |
16 // FFmpeg protocol interface. | 17 // FFmpeg protocol interface. |
17 int OpenContext(URLContext* h, const char* filename, int flags) { | 18 static int OpenContext(URLContext* h, const char* filename, int flags) { |
18 media::FFmpegURLProtocol* protocol; | 19 FFmpegURLProtocol* protocol; |
19 media::FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol); | 20 FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol); |
20 if (!protocol) | 21 if (!protocol) |
21 return AVERROR_IO; | 22 return AVERROR_IO; |
22 | 23 |
23 h->priv_data = protocol; | 24 h->priv_data = protocol; |
24 h->flags = URL_RDONLY; | 25 h->flags = URL_RDONLY; |
25 h->is_streamed = protocol->IsStreaming(); | 26 h->is_streamed = protocol->IsStreaming(); |
26 return 0; | 27 return 0; |
27 } | 28 } |
28 | 29 |
29 int ReadContext(URLContext* h, unsigned char* buf, int size) { | 30 static int ReadContext(URLContext* h, unsigned char* buf, int size) { |
30 media::FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 31 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
31 int result = protocol->Read(size, buf); | 32 int result = protocol->Read(size, buf); |
32 if (result < 0) | 33 if (result < 0) |
33 result = AVERROR_IO; | 34 result = AVERROR_IO; |
34 return result; | 35 return result; |
35 } | 36 } |
36 | 37 |
37 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) | 38 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) |
38 int WriteContext(URLContext* h, const unsigned char* buf, int size) { | 39 static int WriteContext(URLContext* h, const unsigned char* buf, int size) { |
39 #else | 40 #else |
40 int WriteContext(URLContext* h, unsigned char* buf, int size) { | 41 static int WriteContext(URLContext* h, unsigned char* buf, int size) { |
41 #endif | 42 #endif |
42 // We don't support writing. | 43 // We don't support writing. |
43 return AVERROR_IO; | 44 return AVERROR_IO; |
44 } | 45 } |
45 | 46 |
46 int64 SeekContext(URLContext* h, int64 offset, int whence) { | 47 static int64 SeekContext(URLContext* h, int64 offset, int whence) { |
47 media::FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 48 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
48 int64 new_offset = AVERROR_IO; | 49 int64 new_offset = AVERROR_IO; |
49 switch (whence) { | 50 switch (whence) { |
50 case SEEK_SET: | 51 case SEEK_SET: |
51 if (protocol->SetPosition(offset)) | 52 if (protocol->SetPosition(offset)) |
52 protocol->GetPosition(&new_offset); | 53 protocol->GetPosition(&new_offset); |
53 break; | 54 break; |
54 | 55 |
55 case SEEK_CUR: | 56 case SEEK_CUR: |
56 int64 pos; | 57 int64 pos; |
57 if (!protocol->GetPosition(&pos)) | 58 if (!protocol->GetPosition(&pos)) |
(...skipping 15 matching lines...) Expand all Loading... |
73 break; | 74 break; |
74 | 75 |
75 default: | 76 default: |
76 NOTREACHED(); | 77 NOTREACHED(); |
77 } | 78 } |
78 if (new_offset < 0) | 79 if (new_offset < 0) |
79 new_offset = AVERROR_IO; | 80 new_offset = AVERROR_IO; |
80 return new_offset; | 81 return new_offset; |
81 } | 82 } |
82 | 83 |
83 int CloseContext(URLContext* h) { | 84 static int CloseContext(URLContext* h) { |
84 h->priv_data = NULL; | 85 h->priv_data = NULL; |
85 return 0; | 86 return 0; |
86 } | 87 } |
87 | 88 |
88 int LockManagerOperation(void** lock, enum AVLockOp op) { | 89 static int LockManagerOperation(void** lock, enum AVLockOp op) { |
89 switch (op) { | 90 switch (op) { |
90 case AV_LOCK_CREATE: | 91 case AV_LOCK_CREATE: |
91 *lock = new base::Lock(); | 92 *lock = new base::Lock(); |
92 if (!*lock) | 93 if (!*lock) |
93 return 1; | 94 return 1; |
94 return 0; | 95 return 0; |
95 | 96 |
96 case AV_LOCK_OBTAIN: | 97 case AV_LOCK_OBTAIN: |
97 static_cast<base::Lock*>(*lock)->Acquire(); | 98 static_cast<base::Lock*>(*lock)->Acquire(); |
98 return 0; | 99 return 0; |
99 | 100 |
100 case AV_LOCK_RELEASE: | 101 case AV_LOCK_RELEASE: |
101 static_cast<base::Lock*>(*lock)->Release(); | 102 static_cast<base::Lock*>(*lock)->Release(); |
102 return 0; | 103 return 0; |
103 | 104 |
104 case AV_LOCK_DESTROY: | 105 case AV_LOCK_DESTROY: |
105 delete static_cast<base::Lock*>(*lock); | 106 delete static_cast<base::Lock*>(*lock); |
106 *lock = NULL; | 107 *lock = NULL; |
107 return 0; | 108 return 0; |
108 } | 109 } |
109 return 1; | 110 return 1; |
110 } | 111 } |
111 | 112 |
112 } // namespace | |
113 | |
114 //------------------------------------------------------------------------------ | |
115 | |
116 namespace media { | |
117 | |
118 // Use the HTTP protocol to avoid any file path separator issues. | 113 // Use the HTTP protocol to avoid any file path separator issues. |
119 static const char kProtocol[] = "http"; | 114 static const char kProtocol[] = "http"; |
120 | 115 |
121 // Fill out our FFmpeg protocol definition. | 116 // Fill out our FFmpeg protocol definition. |
122 static URLProtocol kFFmpegURLProtocol = { | 117 static URLProtocol kFFmpegURLProtocol = { |
123 kProtocol, | 118 kProtocol, |
124 &OpenContext, | 119 &OpenContext, |
125 &ReadContext, | 120 &ReadContext, |
126 &WriteContext, | 121 &WriteContext, |
127 &SeekContext, | 122 &SeekContext, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 178 } |
184 | 179 |
185 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 180 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
186 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 181 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
187 // This also has the nice property that adding the same FFmpegURLProtocol | 182 // This also has the nice property that adding the same FFmpegURLProtocol |
188 // reference will not generate duplicate entries. | 183 // reference will not generate duplicate entries. |
189 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 184 return StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
190 } | 185 } |
191 | 186 |
192 } // namespace media | 187 } // namespace media |
OLD | NEW |