| 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/ffmpeg/file_protocol.h" | 5 #include "media/ffmpeg/file_protocol.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <io.h> | 10 #include <io.h> |
| 11 #else | 11 #else |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 #endif | 13 #endif |
| 14 #include <fcntl.h> | 14 #include <fcntl.h> |
| 15 | 15 |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/eintr_wrapper.h" | 17 #include "base/eintr_wrapper.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "media/ffmpeg/ffmpeg_common.h" | 19 #include "media/ffmpeg/ffmpeg_common.h" |
| 20 | 20 |
| 21 // warning C4996: 'open': The POSIX name for this item is deprecated. | 21 // warning C4996: 'open': The POSIX name for this item is deprecated. |
| 22 MSVC_PUSH_DISABLE_WARNING(4996) | 22 MSVC_PUSH_DISABLE_WARNING(4996) |
| 23 | 23 |
| 24 namespace { | 24 static int GetHandle(URLContext *h) { |
| 25 | |
| 26 int GetHandle(URLContext *h) { | |
| 27 return static_cast<int>(reinterpret_cast<intptr_t>(h->priv_data)); | 25 return static_cast<int>(reinterpret_cast<intptr_t>(h->priv_data)); |
| 28 } | 26 } |
| 29 | 27 |
| 30 // FFmpeg protocol interface. | 28 // FFmpeg protocol interface. |
| 31 int OpenContext(URLContext* h, const char* filename, int flags) { | 29 static int OpenContext(URLContext* h, const char* filename, int flags) { |
| 32 int access = O_RDONLY; | 30 int access = O_RDONLY; |
| 33 if (flags & URL_RDWR) { | 31 if (flags & URL_RDWR) { |
| 34 access = O_CREAT | O_TRUNC | O_RDWR; | 32 access = O_CREAT | O_TRUNC | O_RDWR; |
| 35 } else if (flags & URL_WRONLY) { | 33 } else if (flags & URL_WRONLY) { |
| 36 access = O_CREAT | O_TRUNC | O_WRONLY; | 34 access = O_CREAT | O_TRUNC | O_WRONLY; |
| 37 } | 35 } |
| 38 #ifdef O_BINARY | 36 #ifdef O_BINARY |
| 39 access |= O_BINARY; | 37 access |= O_BINARY; |
| 40 #endif | 38 #endif |
| 41 int f = open(filename, access, 0666); | 39 int f = open(filename, access, 0666); |
| 42 if (f == -1) | 40 if (f == -1) |
| 43 return AVERROR(ENOENT); | 41 return AVERROR(ENOENT); |
| 44 h->priv_data = reinterpret_cast<void*>(static_cast<intptr_t>(f)); | 42 h->priv_data = reinterpret_cast<void*>(static_cast<intptr_t>(f)); |
| 45 h->is_streamed = false; | 43 h->is_streamed = false; |
| 46 return 0; | 44 return 0; |
| 47 } | 45 } |
| 48 | 46 |
| 49 int ReadContext(URLContext* h, unsigned char* buf, int size) { | 47 static int ReadContext(URLContext* h, unsigned char* buf, int size) { |
| 50 return HANDLE_EINTR(read(GetHandle(h), buf, size)); | 48 return HANDLE_EINTR(read(GetHandle(h), buf, size)); |
| 51 } | 49 } |
| 52 | 50 |
| 53 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) | 51 #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 68, 0) |
| 54 int WriteContext(URLContext* h, const unsigned char* buf, int size) { | 52 static int WriteContext(URLContext* h, const unsigned char* buf, int size) { |
| 55 #else | 53 #else |
| 56 int WriteContext(URLContext* h, unsigned char* buf, int size) { | 54 static int WriteContext(URLContext* h, unsigned char* buf, int size) { |
| 57 #endif | 55 #endif |
| 58 return HANDLE_EINTR(write(GetHandle(h), buf, size)); | 56 return HANDLE_EINTR(write(GetHandle(h), buf, size)); |
| 59 } | 57 } |
| 60 | 58 |
| 61 int64 SeekContext(URLContext* h, int64 offset, int whence) { | 59 static int64 SeekContext(URLContext* h, int64 offset, int whence) { |
| 62 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 63 return _lseeki64(GetHandle(h), static_cast<__int64>(offset), whence); | 61 return _lseeki64(GetHandle(h), static_cast<__int64>(offset), whence); |
| 64 #else | 62 #else |
| 65 COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64_bit); | 63 COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64_bit); |
| 66 return lseek(GetHandle(h), static_cast<off_t>(offset), whence); | 64 return lseek(GetHandle(h), static_cast<off_t>(offset), whence); |
| 67 #endif | 65 #endif |
| 68 } | 66 } |
| 69 | 67 |
| 70 int CloseContext(URLContext* h) { | 68 static int CloseContext(URLContext* h) { |
| 71 return HANDLE_EINTR(close(GetHandle(h))); | 69 return HANDLE_EINTR(close(GetHandle(h))); |
| 72 } | 70 } |
| 73 | 71 |
| 74 } // namespace | |
| 75 | |
| 76 MSVC_POP_WARNING() | 72 MSVC_POP_WARNING() |
| 77 | 73 |
| 78 URLProtocol kFFmpegFileProtocol = { | 74 URLProtocol kFFmpegFileProtocol = { |
| 79 "file", | 75 "file", |
| 80 &OpenContext, | 76 &OpenContext, |
| 81 &ReadContext, | 77 &ReadContext, |
| 82 &WriteContext, | 78 &WriteContext, |
| 83 &SeekContext, | 79 &SeekContext, |
| 84 &CloseContext, | 80 &CloseContext, |
| 85 NULL, // *next | 81 NULL, // *next |
| 86 NULL, // url_read_pause | 82 NULL, // url_read_pause |
| 87 NULL, // url_read_seek | 83 NULL, // url_read_seek |
| 88 &GetHandle | 84 &GetHandle |
| 89 }; | 85 }; |
| OLD | NEW |