1 // Copyright 2020 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 #include "cast/standalone_sender/ffmpeg_glue.h"
6 
7 #include "util/osp_logging.h"
8 
9 namespace openscreen {
10 namespace cast {
11 namespace internal {
12 
CreateAVFormatContextForFile(const char * path)13 AVFormatContext* CreateAVFormatContextForFile(const char* path) {
14   AVFormatContext* format_context = nullptr;
15   int result = avformat_open_input(&format_context, path, nullptr, nullptr);
16   if (result < 0) {
17     OSP_LOG_ERROR << "Cannot open " << path << ": " << av_err2str(result);
18     return nullptr;
19   }
20   result = avformat_find_stream_info(format_context, nullptr);
21   if (result < 0) {
22     avformat_close_input(&format_context);
23     OSP_LOG_ERROR << "Cannot find stream info in " << path << ": "
24                   << av_err2str(result);
25     return nullptr;
26   }
27   return format_context;
28 }
29 
30 }  // namespace internal
31 }  // namespace cast
32 }  // namespace openscreen
33