| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_AV_FORMAT_CONTEXT_H_ |
| 6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_AV_FORMAT_CONTEXT_H_ |
| 7 |
| 8 #include "services/media/framework_ffmpeg/av_io_context.h" |
| 9 #include "services/media/framework_ffmpeg/ffmpeg_init.h" |
| 10 extern "C" { |
| 11 #include "third_party/ffmpeg/libavcodec/avcodec.h" |
| 12 #include "third_party/ffmpeg/libavformat/avformat.h" |
| 13 } |
| 14 |
| 15 namespace mojo { |
| 16 namespace media { |
| 17 |
| 18 struct AVFormatContextDeleter { |
| 19 inline void operator()(AVFormatContext* ptr) const { |
| 20 avformat_free_context(ptr); |
| 21 } |
| 22 }; |
| 23 |
| 24 using AvFormatContextPtr = |
| 25 std::unique_ptr<AVFormatContext, AVFormatContextDeleter>; |
| 26 |
| 27 struct AvFormatContext { |
| 28 static AvFormatContextPtr OpenInput(const AvIoContextPtr& io_context) { |
| 29 InitFfmpeg(); |
| 30 |
| 31 AVFormatContext* format_context = avformat_alloc_context(); |
| 32 format_context->flags |= AVFMT_FLAG_CUSTOM_IO | AVFMT_FLAG_FAST_SEEK; |
| 33 format_context->pb = io_context.get(); |
| 34 |
| 35 // TODO(dalesat): This synchronous operation may take a long time. |
| 36 int r = avformat_open_input(&format_context, nullptr, nullptr, nullptr); |
| 37 if (r < 0) { |
| 38 delete format_context; |
| 39 format_context = nullptr; |
| 40 } |
| 41 |
| 42 return AvFormatContextPtr(format_context); |
| 43 } |
| 44 }; |
| 45 |
| 46 } // namespace media |
| 47 } // namespace mojo |
| 48 |
| 49 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_AV_FORMAT_CONTEXT_H_ |
| OLD | NEW |