OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "services/media/framework/parts/reader.h" | 6 #include "services/media/framework/parts/reader.h" |
7 #include "services/media/framework_ffmpeg/av_io_context.h" | 7 #include "services/media/framework_ffmpeg/av_io_context.h" |
8 #include "services/media/framework_ffmpeg/ffmpeg_init.h" | 8 #include "services/media/framework_ffmpeg/ffmpeg_init.h" |
9 extern "C" { | 9 extern "C" { |
10 #include "third_party/ffmpeg/libavformat/avio.h" | 10 #include "third_party/ffmpeg/libavformat/avio.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 // static | 24 // static |
25 AvIoContextPtr AvIoContext::Create(std::shared_ptr<Reader> reader) { | 25 AvIoContextPtr AvIoContext::Create(std::shared_ptr<Reader> reader) { |
26 // Internal buffer size used by AVIO for reading. | 26 // Internal buffer size used by AVIO for reading. |
27 constexpr int kBufferSize = 32 * 1024; | 27 constexpr int kBufferSize = 32 * 1024; |
28 | 28 |
29 InitFfmpeg(); | 29 InitFfmpeg(); |
30 | 30 |
31 AVIOContext* result = avio_alloc_context( | 31 AVIOContext* result = avio_alloc_context( |
32 static_cast<unsigned char*>(av_malloc(kBufferSize)), | 32 static_cast<unsigned char*>(av_malloc(kBufferSize)), kBufferSize, |
33 kBufferSize, | 33 0, // write_flag |
34 0, // write_flag | 34 new AvIoContext(reader), &Read, nullptr, &Seek); |
35 new AvIoContext(reader), | |
36 &Read, | |
37 nullptr, | |
38 &Seek); | |
39 | 35 |
40 // Ensure FFmpeg only tries to seek when we know how. | 36 // Ensure FFmpeg only tries to seek when we know how. |
41 result->seekable = reader->CanSeek() ? AVIO_SEEKABLE_NORMAL : 0; | 37 result->seekable = reader->CanSeek() ? AVIO_SEEKABLE_NORMAL : 0; |
42 | 38 |
43 // Ensure writing is disabled. | 39 // Ensure writing is disabled. |
44 result->write_flag = 0; | 40 result->write_flag = 0; |
45 | 41 |
46 return AvIoContextPtr(result); | 42 return AvIoContextPtr(result); |
47 } | 43 } |
48 | 44 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 99 |
104 CHECK(size_ == -1 || position_ < size_) << "position out of range"; | 100 CHECK(size_ == -1 || position_ < size_) << "position out of range"; |
105 int64_t result = reader_->SetPosition(position_); | 101 int64_t result = reader_->SetPosition(position_); |
106 if (result == -1) { | 102 if (result == -1) { |
107 LOG(ERROR) << "seek failed"; | 103 LOG(ERROR) << "seek failed"; |
108 return AVERROR(EIO); | 104 return AVERROR(EIO); |
109 } | 105 } |
110 return position_; | 106 return position_; |
111 } | 107 } |
112 | 108 |
113 | 109 } // namespace media |
114 } // namespace media | 110 } // namespace mojo |
115 } // namespace mojo | |
OLD | NEW |