Changeset a74d5452eb0c1b7846e14090c1063169ebd9681a
- Timestamp:
- 03/04/08 15:35:01
(6 months ago)
- Author:
- Jean-Paul Saman <jpsaman@videolan.org>
- git-committer:
- Jean-Paul Saman <jpsaman@videolan.org> 1204641301 +0100
- git-parent:
[93b4565847b0f951ac5cf036d14d5b0544cfe64c]
- git-author:
- Jean-Paul Saman <jpsaman@videolan.org> 1204481576 +0100
- Message:
Check malloc return values and small cleanup.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r079a181 |
ra74d545 |
|
| 141 | 141 | |
|---|
| 142 | 142 | enum { |
|---|
| 143 | | |
|---|
| 144 | 143 | STATE_NOSYNC, |
|---|
| 145 | 144 | STATE_SYNC, |
|---|
| … | … | |
| 250 | 249 | p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; |
|---|
| 251 | 250 | p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra ); |
|---|
| | 251 | if( !p_dec->fmt_out.p_extra ) |
|---|
| | 252 | { |
|---|
| | 253 | p_dec->fmt_out.i_extra = 0; |
|---|
| | 254 | return VLC_ENOMEM; |
|---|
| | 255 | } |
|---|
| 252 | 256 | memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, |
|---|
| 253 | 257 | p_dec->fmt_in.i_extra ); |
|---|
| … | … | |
| 353 | 357 | if( !p_dec->fmt_out.i_extra ) |
|---|
| 354 | 358 | { |
|---|
| | 359 | p_dec->fmt_out.p_extra = malloc( 2 ); |
|---|
| | 360 | if( !p_dec->fmt_out.p_extra ) |
|---|
| | 361 | { |
|---|
| | 362 | p_dec->fmt_out.i_extra = 0; |
|---|
| | 363 | return 0; |
|---|
| | 364 | } |
|---|
| 355 | 365 | p_dec->fmt_out.i_extra = 2; |
|---|
| 356 | | p_dec->fmt_out.p_extra = malloc( 2 ); |
|---|
| 357 | 366 | ((uint8_t *)p_dec->fmt_out.p_extra)[0] = |
|---|
| 358 | 367 | (i_profile + 1) << 3 | (i_sample_rate_idx >> 1); |
|---|
| … | … | |
| 366 | 375 | return i_frame_size - *pi_header_size; |
|---|
| 367 | 376 | } |
|---|
| | 377 | |
|---|
| 368 | 378 | /**************************************************************************** |
|---|
| 369 | 379 | * LOAS helpers |
|---|
| … | … | |
| 374 | 384 | return ( ( p_header[1] & 0x1f ) << 8 ) + p_header[2]; |
|---|
| 375 | 385 | } |
|---|
| | 386 | |
|---|
| 376 | 387 | static int Mpeg4GAProgramConfigElement( bs_t *s ) |
|---|
| 377 | 388 | { |
|---|
| … | … | |
| 406 | 417 | return 0; |
|---|
| 407 | 418 | } |
|---|
| | 419 | |
|---|
| 408 | 420 | static int Mpeg4GASpecificConfig( mpeg4_cfg_t *p_cfg, bs_t *s ) |
|---|
| 409 | 421 | { |
|---|
| … | … | |
| 437 | 449 | return 0; |
|---|
| 438 | 450 | } |
|---|
| | 451 | |
|---|
| 439 | 452 | static int Mpeg4ReadAudioObjectType( bs_t *s ) |
|---|
| 440 | 453 | { |
|---|
| … | … | |
| 444 | 457 | return i_type; |
|---|
| 445 | 458 | } |
|---|
| | 459 | |
|---|
| 446 | 460 | static int Mpeg4ReadAudioSamplerate( bs_t *s ) |
|---|
| 447 | 461 | { |
|---|
| … | … | |
| 451 | 465 | return bs_read( s, 24 ); |
|---|
| 452 | 466 | } |
|---|
| | 467 | |
|---|
| 453 | 468 | static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_t *p_extra, bs_t *s, int i_max_size ) |
|---|
| 454 | 469 | { |
|---|
| … | … | |
| 480 | 495 | memset( p_cfg, 0, sizeof(*p_cfg) ); |
|---|
| 481 | 496 | *pi_extra = 0; |
|---|
| 482 | | |
|---|
| | 497 | |
|---|
| 483 | 498 | p_cfg->i_object_type = Mpeg4ReadAudioObjectType( s ); |
|---|
| 484 | 499 | p_cfg->i_samplerate = Mpeg4ReadAudioSamplerate( s ); |
|---|
| … | … | |
| 566 | 581 | break; |
|---|
| 567 | 582 | } |
|---|
| | 583 | |
|---|
| 568 | 584 | if( p_cfg->extension.i_object_type != 5 && i_max_size > 0 && i_max_size - (bs_pos(s) - i_pos_start) >= 16 && |
|---|
| 569 | 585 | bs_read( s, 11 ) == 0x2b7 ) |
|---|
| … | … | |
| 734 | 750 | if( !bs_read1( &s ) ) |
|---|
| 735 | 751 | { |
|---|
| 736 | | if( !LatmReadStreamMuxConfiguration( &p_sys->latm, &s ) && p_sys->latm.i_streams > 0 ) |
|---|
| | 752 | if( !LatmReadStreamMuxConfiguration( &p_sys->latm, &s ) && |
|---|
| | 753 | p_sys->latm.i_streams > 0 ) |
|---|
| 737 | 754 | { |
|---|
| 738 | 755 | const latm_stream_t *st = &p_sys->latm.stream[0]; |
|---|
| … | … | |
| 747 | 764 | p_dec->fmt_out.i_extra = st->i_extra; |
|---|
| 748 | 765 | p_dec->fmt_out.p_extra = malloc( st->i_extra ); |
|---|
| | 766 | if( !p_dec->fmt_out.p_extra ) |
|---|
| | 767 | { |
|---|
| | 768 | p_dec->fmt_out.i_extra = 0; |
|---|
| | 769 | return 0; |
|---|
| | 770 | } |
|---|
| 749 | 771 | memcpy( p_dec->fmt_out.p_extra, st->extra, st->i_extra ); |
|---|
| 750 | 772 | } |
|---|
| … | … | |
| 790 | 812 | pi_payload[i_program][i_layer] = st->i_frame_length / 8; /* XXX not correct */ |
|---|
| 791 | 813 | } |
|---|
| 792 | | else if( st->i_frame_length_type == 3 || st->i_frame_length_type == 5 || st->i_frame_length_type == 7 ) |
|---|
| | 814 | else if( ( st->i_frame_length_type == 3 ) || |
|---|
| | 815 | ( st->i_frame_length_type == 5 ) || |
|---|
| | 816 | ( st->i_frame_length_type == 7 ) ) |
|---|
| 793 | 817 | { |
|---|
| 794 | 818 | bs_skip( &s, 2 ); // muxSlotLengthCoded |
|---|
| … | … | |
| 857 | 881 | pi_payload[i_program][i_layer] = st->i_frame_length / 8; /* XXX not correct */ |
|---|
| 858 | 882 | } |
|---|
| 859 | | else if( st->i_frame_length_type == 3 || st->i_frame_length_type == 5 || st->i_frame_length_type == 7 ) |
|---|
| | 883 | else if( ( st->i_frame_length_type == 3 ) || |
|---|
| | 884 | ( st->i_frame_length_type == 5 ) || |
|---|
| | 885 | ( st->i_frame_length_type == 7 ) ) |
|---|
| 860 | 886 | { |
|---|
| 861 | 887 | bs_read( &s, 2 ); // muxSlotLengthCoded |
|---|
| … | … | |
| 1016 | 1042 | /* TODO: If p_block == NULL, flush the buffer without checking the |
|---|
| 1017 | 1043 | * next sync word */ |
|---|
| | 1044 | if( p_sys->bytestream.p_block == NULL ) |
|---|
| | 1045 | { |
|---|
| | 1046 | p_sys->i_state = STATE_NOSYNC; |
|---|
| | 1047 | block_BytestreamFlush( &p_sys->bytestream ); |
|---|
| | 1048 | return NULL; |
|---|
| | 1049 | } |
|---|
| 1018 | 1050 | |
|---|
| 1019 | 1051 | /* Check if next expected frame contains the sync word */ |
|---|
| … | … | |
| 1026 | 1058 | } |
|---|
| 1027 | 1059 | |
|---|
| 1028 | | assert( p_sys->i_type == TYPE_ADTS || p_sys->i_type == TYPE_LOAS ); |
|---|
| 1029 | | if( ( p_sys->i_type == TYPE_ADTS && ( p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0 ) ) || |
|---|
| 1030 | | ( p_sys->i_type == TYPE_LOAS && ( p_header[0] != 0x56 || (p_header[1] & 0xe0) != 0xe0 ) ) ) |
|---|
| | 1060 | assert( (p_sys->i_type == TYPE_ADTS) || (p_sys->i_type == TYPE_LOAS) ); |
|---|
| | 1061 | if( ( ( p_sys->i_type == TYPE_ADTS ) && |
|---|
| | 1062 | ( p_header[0] != 0xff || (p_header[1] & 0xf6) != 0xf0 ) ) || |
|---|
| | 1063 | ( ( p_sys->i_type == TYPE_LOAS ) && |
|---|
| | 1064 | ( p_header[0] != 0x56 || (p_header[1] & 0xe0) != 0xe0 ) ) ) |
|---|
| 1031 | 1065 | { |
|---|
| 1032 | 1066 | msg_Dbg( p_dec, "emulated sync word " |
|---|
| … | … | |
| 1105 | 1139 | } |
|---|
| 1106 | 1140 | |
|---|
| 1107 | | |
|---|
| 1108 | 1141 | /***************************************************************************** |
|---|
| 1109 | 1142 | * SetupBuffer: |
|---|
| … | … | |
| 1152 | 1185 | free( p_dec->p_sys ); |
|---|
| 1153 | 1186 | } |
|---|
| 1154 | | |
|---|
| 1155 | | |
|---|