OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 18 #include "base/file_util.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "media/ffmpeg/ffmpeg_common.h" | 20 #include "media/ffmpeg/ffmpeg_common.h" |
20 | 21 |
21 // warning C4996: 'open': The POSIX name for this item is deprecated. | 22 // warning C4996: 'open': The POSIX name for this item is deprecated. |
22 MSVC_PUSH_DISABLE_WARNING(4996) | 23 MSVC_PUSH_DISABLE_WARNING(4996) |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 int GetHandle(URLContext *h) { | 27 int GetHandle(URLContext *h) { |
(...skipping 13 matching lines...) Expand all Loading... | |
40 #endif | 41 #endif |
41 int f = open(filename, access, 0666); | 42 int f = open(filename, access, 0666); |
42 if (f == -1) | 43 if (f == -1) |
43 return AVERROR(ENOENT); | 44 return AVERROR(ENOENT); |
44 h->priv_data = reinterpret_cast<void*>(static_cast<intptr_t>(f)); | 45 h->priv_data = reinterpret_cast<void*>(static_cast<intptr_t>(f)); |
45 h->is_streamed = false; | 46 h->is_streamed = false; |
46 return 0; | 47 return 0; |
47 } | 48 } |
48 | 49 |
49 int ReadContext(URLContext* h, unsigned char* buf, int size) { | 50 int ReadContext(URLContext* h, unsigned char* buf, int size) { |
50 return read(GetHandle(h), buf, size); | 51 return HANDLE_EINTR(read(GetHandle(h), buf, size)); |
51 } | 52 } |
52 | 53 |
53 int WriteContext(URLContext* h, unsigned char* buf, int size) { | 54 int WriteContext(URLContext* h, unsigned char* buf, int size) { |
54 return write(GetHandle(h), buf, size); | 55 return HANDLE_EINTR(write(GetHandle(h), buf, size)); |
55 } | 56 } |
56 | 57 |
57 offset_t SeekContext(URLContext* h, offset_t offset, int whence) { | 58 int64 SeekContext(URLContext* h, int64 offset, int whence) { |
58 #if defined(OS_WIN) | 59 return lseek(GetHandle(h), static_cast<off_t>(offset), whence); |
wtc
2010/05/19 17:20:42
MSVC has _lseeki64, which takes a 64-bit offset ar
agl
2010/05/19 18:07:32
I figured that off_t would be 64-bit on Windows, b
awong
2010/05/19 18:12:56
Doesn't off_t change on glibc depending on the var
wtc
2010/05/19 18:44:55
We can add a static assertion to assert that sizeo
| |
59 return lseek(GetHandle(h), static_cast<long>(offset), whence); | |
60 #else | |
61 return lseek(GetHandle(h), offset, whence); | |
62 #endif | |
63 } | 60 } |
64 | 61 |
65 int CloseContext(URLContext* h) { | 62 int CloseContext(URLContext* h) { |
66 return close(GetHandle(h)); | 63 return HANDLE_EINTR(close(GetHandle(h))); |
67 } | 64 } |
68 | 65 |
69 } // namespace | 66 } // namespace |
70 | 67 |
71 MSVC_POP_WARNING() | 68 MSVC_POP_WARNING() |
72 | 69 |
73 URLProtocol kFFmpegFileProtocol = { | 70 URLProtocol kFFmpegFileProtocol = { |
74 "file", | 71 "file", |
75 &OpenContext, | 72 &OpenContext, |
76 &ReadContext, | 73 &ReadContext, |
77 &WriteContext, | 74 &WriteContext, |
78 &SeekContext, | 75 &SeekContext, |
79 &CloseContext, | 76 &CloseContext, |
80 NULL, // *next | 77 NULL, // *next |
81 NULL, // url_read_pause | 78 NULL, // url_read_pause |
82 NULL, // url_read_seek | 79 NULL, // url_read_seek |
83 &GetHandle | 80 &GetHandle |
84 }; | 81 }; |
OLD | NEW |