list: Decide the entry eliminator of list at its initialization.
[L-SMASH.git] / codecs / mp4v.c
blob907d12eaf44384fbdb69096357043cf36b662fdc
1 /*****************************************************************************
2 * mp4v.c
3 *****************************************************************************
4 * Copyright (C) 2011-2017 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
23 #include "common/internal.h" /* must be placed first */
25 #include "core/box.h"
27 #include "mp4a.h" /* ugly hack for the definition of mp4a_audioProfileLevelIndication */
28 #include "mp4sys.h"
30 int mp4v_update_bitrate( isom_stbl_t *stbl, isom_mdhd_t *mdhd, uint32_t sample_description_index )
32 isom_visual_entry_t *mp4v = (isom_visual_entry_t *)lsmash_list_get_entry_data( &stbl->stsd->list, sample_description_index );
33 if( LSMASH_IS_NON_EXISTING_BOX( mp4v ) )
34 return LSMASH_ERR_INVALID_DATA;
35 isom_esds_t *esds = (isom_esds_t *)isom_get_extension_box_format( &mp4v->extensions, ISOM_BOX_TYPE_ESDS );
36 if( LSMASH_IS_NON_EXISTING_BOX( esds ) || !esds->ES )
37 return LSMASH_ERR_INVALID_DATA;
38 uint32_t bufferSizeDB;
39 uint32_t maxBitrate;
40 uint32_t avgBitrate;
41 int err = isom_calculate_bitrate_description( stbl, mdhd, &bufferSizeDB, &maxBitrate, &avgBitrate, sample_description_index );
42 if( err < 0 )
43 return err;
44 /* FIXME: avgBitrate is 0 only if VBR in proper. */
45 return mp4sys_update_DecoderConfigDescriptor( esds->ES, bufferSizeDB, maxBitrate, 0 );