Skip to content

Commit

Permalink
Add support for aspect ratio VUI parameters in H264Parser.
Browse files Browse the repository at this point in the history
BUG=340426

Review URL: https://codereview.chromium.org/145973012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248880 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
damienv@chromium.org committed Feb 5, 2014
1 parent b083ff9 commit 07b1823
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 30 additions & 1 deletion media/filters/h264_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ H264SEIMessage::H264SEIMessage() {
} \
} while (0)

enum AspectRatioIdc {
kExtendedSar = 255,
};

// ISO 14496 part 10
// VUI parameters: Table E-1 "Meaning of sample aspect ratio indicator"
static const int kTableSarWidth[] = {
0, 1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160, 4, 3, 2
};
static const int kTableSarHeight[] = {
0, 1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1
};
COMPILE_ASSERT(arraysize(kTableSarWidth) == arraysize(kTableSarHeight),
sar_tables_must_have_same_size);

H264Parser::H264Parser() {
Reset();
}
Expand Down Expand Up @@ -672,7 +687,21 @@ H264Parser::Result H264Parser::ParseSPS(int* sps_id) {

READ_BOOL_OR_RETURN(&sps->vui_parameters_present_flag);
if (sps->vui_parameters_present_flag) {
DVLOG(1) << "VUI parameters present in SPS, ignoring";
bool aspect_ratio_info_present_flag;
READ_BOOL_OR_RETURN(&aspect_ratio_info_present_flag);
if (aspect_ratio_info_present_flag) {
int aspect_ratio_idc;
READ_BITS_OR_RETURN(8, &aspect_ratio_idc);
if (aspect_ratio_idc == kExtendedSar) {
READ_BITS_OR_RETURN(16, &sps->sar_width);
READ_BITS_OR_RETURN(16, &sps->sar_height);
} else {
const int max_aspect_ratio_idc = arraysize(kTableSarWidth) - 1;
IN_RANGE_OR_RETURN(aspect_ratio_idc, 0, max_aspect_ratio_idc);
sps->sar_width = kTableSarWidth[aspect_ratio_idc];
sps->sar_height = kTableSarHeight[aspect_ratio_idc];
}
}
}

// If an SPS with the same id already exists, replace it.
Expand Down
2 changes: 2 additions & 0 deletions media/filters/h264_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ struct MEDIA_EXPORT H264SPS {
int frame_crop_bottom_offset;
bool vui_parameters_present_flag;
int chroma_array_type;
int sar_width; // Set to 0 when not specified.
int sar_height; // Set to 0 when not specified.
};

struct MEDIA_EXPORT H264PPS {
Expand Down

0 comments on commit 07b1823

Please sign in to comment.