xref: /aosp_15_r20/external/openscreen/cast/standalone_sender/ffmpeg_glue.cc (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
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 <libavcodec/version.h>
8 
9 #include "util/osp_logging.h"
10 
11 namespace openscreen {
12 namespace cast {
13 namespace internal {
14 
CreateAVFormatContextForFile(const char * path)15 AVFormatContext* CreateAVFormatContextForFile(const char* path) {
16   AVFormatContext* format_context = nullptr;
17 #if LIBAVCODEC_VERSION_MAJOR < 59
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20   av_register_all();
21 #pragma GCC diagnostic pop
22 #endif  // LIBAVCODEC_VERSION_MAJOR < 59
23 
24   int result = avformat_open_input(&format_context, path, nullptr, nullptr);
25   if (result < 0) {
26     OSP_LOG_ERROR << "Cannot open " << path << ": " << av_err2str(result);
27     return nullptr;
28   }
29   result = avformat_find_stream_info(format_context, nullptr);
30   if (result < 0) {
31     avformat_close_input(&format_context);
32     OSP_LOG_ERROR << "Cannot find stream info in " << path << ": "
33                   << av_err2str(result);
34     return nullptr;
35   }
36   return format_context;
37 }
38 
39 }  // namespace internal
40 }  // namespace cast
41 }  // namespace openscreen
42