MythTV  master
mediacodeccontext.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 MythTV Developers <mythtv-dev@mythtv.org>
3 //
4 // This is part of MythTV (https://www.mythtv.org)
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 //
24 
25 #include "mediacodeccontext.h"
26 
27 #include "mythlogging.h"
28 
29 extern "C" {
30  #include "libavutil/pixfmt.h"
31  #include "libavutil/hwcontext.h"
32  #include "libavcodec/avcodec.h"
33 }
34 
35 #define LOC QString("MEDIACODEC: ")
36 
38  AVCodec **ppCodec,
39  const QString &decoder,
40  uint stream_type,
41  AVPixelFormat &pix_fmt)
42 {
43  enum AVHWDeviceType type = AV_HWDEVICE_TYPE_MEDIACODEC;
44 
45  AVPixelFormat fmt = AV_PIX_FMT_NONE;
46  if (decoder == "mediacodec")
47  {
48  QString decodername = QString((*ppCodec)->name) + "_mediacodec";
49  if (decodername == "mpeg2video_mediacodec")
50  decodername = "mpeg2_mediacodec";
51  AVCodec *newCodec = avcodec_find_decoder_by_name (decodername.toLocal8Bit());
52  if (newCodec)
53  {
54  *ppCodec = newCodec;
55  fmt = AV_PIX_FMT_MEDIACODEC;
56  }
57  else
58  LOG(VB_PLAYBACK, LOG_INFO, LOC +
59  QString("Decoder %1 does not support device type %2.")
60  .arg((*ppCodec)->name).arg(av_hwdevice_get_type_name(type)));
61  }
62 
63  if (fmt == AV_PIX_FMT_NONE)
64  return (MythCodecID)(kCodec_MPEG1 + (stream_type - 1));
65  else
66  {
67  LOG(VB_PLAYBACK, LOG_INFO, LOC +
68  QString("Decoder %1 supports device type %2.")
69  .arg((*ppCodec)->name).arg(av_hwdevice_get_type_name(type)));
70  pix_fmt = fmt;
71  return (MythCodecID)(kCodec_MPEG1_MEDIACODEC + (stream_type - 1));
72  }
73 }
MythCodecID
Definition: mythcodecid.h:10
unsigned int uint
Definition: compat.h:140
#define LOC
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
static MythCodecID GetBestSupportedCodec(AVCodec **ppCodec, const QString &decoder, uint stream_type, AVPixelFormat &pix_fmt)