FFmpeg
h2645_vui.c
Go to the documentation of this file.
1 /*
2  * Common H.264/HEVC VUI Parameter decoding
3  *
4  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
5  * Copyright (C) 2012 - 2013 Guillaume Martres
6  * Copyright (C) 2012 - 2013 Mickael Raulet
7  * Copyright (C) 2012 - 2013 Gildas Cocherel
8  * Copyright (C) 2013 Vittorio Giovara
9  *
10  * This file is part of FFmpeg.
11  *
12  * FFmpeg is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * FFmpeg is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with FFmpeg; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 #include "libavutil/log.h"
28 #include "libavutil/pixdesc.h"
29 
30 #include "get_bits.h"
31 #include "golomb.h"
32 #include "h2645data.h"
33 #include "h2645_vui.h"
34 
35 #define EXTENDED_SAR 255
36 
38 {
39  int aspect_ratio_info_present_flag;
40 
41  av_log(logctx, AV_LOG_DEBUG, "Decoding VUI\n");
42 
43  aspect_ratio_info_present_flag = get_bits1(gb);
44  if (aspect_ratio_info_present_flag) {
45  uint8_t aspect_ratio_idc = get_bits(gb, 8);
46  if (aspect_ratio_idc < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect))
47  vui->sar = ff_h2645_pixel_aspect[aspect_ratio_idc];
48  else if (aspect_ratio_idc == EXTENDED_SAR) {
49  vui->sar.num = get_bits(gb, 16);
50  vui->sar.den = get_bits(gb, 16);
51  } else
52  av_log(logctx, AV_LOG_WARNING,
53  "Unknown SAR index: %u.\n", aspect_ratio_idc);
54  } else
55  vui->sar = (AVRational){ 0, 1 };
56 
60 
63  vui->video_format = get_bits(gb, 3);
67  vui->colour_primaries = get_bits(gb, 8);
68  vui->transfer_characteristics = get_bits(gb, 8);
69  vui->matrix_coeffs = get_bits(gb, 8);
70 
71  // Set invalid values to "unspecified"
78  }
79  }
80 
87  else
89  } else
91 }
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
EXTENDED_SAR
#define EXTENDED_SAR
Definition: h2645_vui.c:35
H2645VUI::matrix_coeffs
enum AVColorSpace matrix_coeffs
Definition: h2645_vui.h:39
pixdesc.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:561
H2645VUI::sar
AVRational sar
Definition: h2645_vui.h:28
H2645VUI::colour_primaries
enum AVColorPrimaries colour_primaries
Definition: h2645_vui.h:37
H2645VUI::video_full_range_flag
int video_full_range_flag
Definition: h2645_vui.h:35
H2645VUI::video_signal_type_present_flag
int video_signal_type_present_flag
Definition: h2645_vui.h:33
golomb.h
exp golomb vlc stuff
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:325
H2645VUI::chroma_loc_info_present_flag
int chroma_loc_info_present_flag
Definition: h2645_vui.h:41
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:3264
GetBitContext
Definition: get_bits.h:107
H2645VUI::chroma_sample_loc_type_bottom_field
int chroma_sample_loc_type_bottom_field
Definition: h2645_vui.h:43
AVRational::num
int num
Numerator.
Definition: rational.h:59
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
H2645VUI::chroma_sample_loc_type_top_field
int chroma_sample_loc_type_top_field
Definition: h2645_vui.h:42
H2645VUI::overscan_appropriate_flag
int overscan_appropriate_flag
Definition: h2645_vui.h:31
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
get_bits.h
h2645data.h
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:536
H2645VUI::overscan_info_present_flag
int overscan_info_present_flag
Definition: h2645_vui.h:30
H2645VUI::colour_description_present_flag
int colour_description_present_flag
Definition: h2645_vui.h:36
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:682
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:378
H2645VUI
Definition: h2645_vui.h:27
av_color_primaries_name
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:3222
H2645VUI::transfer_characteristics
enum AVColorTransferCharacteristic transfer_characteristics
Definition: h2645_vui.h:38
H2645VUI::chroma_location
enum AVChromaLocation chroma_location
Definition: h2645_vui.h:44
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:681
log.h
ff_h2645_pixel_aspect
const AVRational ff_h2645_pixel_aspect[]
Definition: h2645data.c:21
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:590
h2645_vui.h
ff_h2645_decode_common_vui_params
void ff_h2645_decode_common_vui_params(GetBitContext *gb, H2645VUI *vui, void *logctx)
Definition: h2645_vui.c:37
U
#define U(x)
Definition: vpx_arith.h:37
get_ue_golomb_31
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition: golomb.h:120
AVRational::den
int den
Denominator.
Definition: rational.h:60
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_color_transfer_name
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:3243
H2645VUI::video_format
int video_format
Definition: h2645_vui.h:34