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_IO; | 23 return AVERROR(EIO); |
24 | 24 |
25 h->priv_data = protocol; | 25 h->priv_data = protocol; |
26 h->flags = URL_RDONLY; | 26 h->flags = URL_RDONLY; |
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 ReadContext(URLContext* h, unsigned char* buf, int size) { | 31 static int ReadContext(URLContext* h, unsigned char* buf, int size) { |
32 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 32 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
33 int result = protocol->Read(size, buf); | 33 int result = protocol->Read(size, buf); |
34 if (result < 0) | 34 if (result < 0) |
35 result = AVERROR_IO; | 35 result = AVERROR(EIO); |
36 return result; | 36 return result; |
37 } | 37 } |
38 | 38 |
39 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) | 39 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) |
40 static int WriteContext(URLContext* h, const unsigned char* buf, int size) { | 40 static int WriteContext(URLContext* h, const unsigned char* buf, int size) { |
41 #else | 41 #else |
42 static int WriteContext(URLContext* h, unsigned char* buf, int size) { | 42 static int WriteContext(URLContext* h, unsigned char* buf, int size) { |
43 #endif | 43 #endif |
44 // We don't support writing. | 44 // We don't support writing. |
45 return AVERROR_IO; | 45 return AVERROR(EIO); |
46 } | 46 } |
47 | 47 |
48 static int64 SeekContext(URLContext* h, int64 offset, int whence) { | 48 static int64 SeekContext(URLContext* h, int64 offset, int whence) { |
49 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); | 49 FFmpegURLProtocol* protocol = ToProtocol(h->priv_data); |
50 int64 new_offset = AVERROR_IO; | 50 int64 new_offset = AVERROR(EIO); |
51 switch (whence) { | 51 switch (whence) { |
52 case SEEK_SET: | 52 case SEEK_SET: |
53 if (protocol->SetPosition(offset)) | 53 if (protocol->SetPosition(offset)) |
54 protocol->GetPosition(&new_offset); | 54 protocol->GetPosition(&new_offset); |
55 break; | 55 break; |
56 | 56 |
57 case SEEK_CUR: | 57 case SEEK_CUR: |
58 int64 pos; | 58 int64 pos; |
59 if (!protocol->GetPosition(&pos)) | 59 if (!protocol->GetPosition(&pos)) |
60 break; | 60 break; |
(...skipping 10 matching lines...) Expand all Loading... |
71 break; | 71 break; |
72 | 72 |
73 case AVSEEK_SIZE: | 73 case AVSEEK_SIZE: |
74 protocol->GetSize(&new_offset); | 74 protocol->GetSize(&new_offset); |
75 break; | 75 break; |
76 | 76 |
77 default: | 77 default: |
78 NOTREACHED(); | 78 NOTREACHED(); |
79 } | 79 } |
80 if (new_offset < 0) | 80 if (new_offset < 0) |
81 new_offset = AVERROR_IO; | 81 new_offset = AVERROR(EIO); |
82 return new_offset; | 82 return new_offset; |
83 } | 83 } |
84 | 84 |
85 static int CloseContext(URLContext* h) { | 85 static int CloseContext(URLContext* h) { |
86 h->priv_data = NULL; | 86 h->priv_data = NULL; |
87 return 0; | 87 return 0; |
88 } | 88 } |
89 | 89 |
90 static int LockManagerOperation(void** lock, enum AVLockOp op) { | 90 static int LockManagerOperation(void** lock, enum AVLockOp op) { |
91 switch (op) { | 91 switch (op) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 | 180 |
181 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { | 181 std::string FFmpegGlue::GetProtocolKey(FFmpegURLProtocol* protocol) { |
182 // Use the FFmpegURLProtocol's memory address to generate the unique string. | 182 // Use the FFmpegURLProtocol's memory address to generate the unique string. |
183 // This also has the nice property that adding the same FFmpegURLProtocol | 183 // This also has the nice property that adding the same FFmpegURLProtocol |
184 // reference will not generate duplicate entries. | 184 // reference will not generate duplicate entries. |
185 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); | 185 return base::StringPrintf("%s://%p", kProtocol, static_cast<void*>(protocol)); |
186 } | 186 } |
187 | 187 |
188 } // namespace media | 188 } // namespace media |
OLD | NEW |