/***************************************************************************** * OpenCommon: *****************************************************************************/ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_CODEC_DTS ) return VLC_EGENERIC; /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = malloc(sizeof(*p_sys)) ) == NULL ) return VLC_ENOMEM; /* Misc init */ p_sys->b_packetizer = b_packetizer; p_sys->i_state = STATE_NOSYNC; date_Set( &p_sys->end_date, 0 ); p_sys->b_dts_hd = false; p_sys->i_pts = VLC_TS_INVALID; block_BytestreamInit( &p_sys->bytestream ); /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; p_dec->fmt_out.i_codec = VLC_CODEC_DTS; p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */ /* Set callback */ p_dec->pf_decode_audio = DecodeBlock; p_dec->pf_packetize = DecodeBlock; return VLC_SUCCESS; }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', 'g', '1' ) && p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', 'g', '2' ) && p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', 'g', 'v' ) ) { return VLC_EGENERIC; } es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC('m','p','g','v') ); p_dec->pf_packetize = Packetize; p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) ); /* Misc init */ p_sys->i_state = STATE_NOSYNC; p_sys->bytestream = block_BytestreamInit( p_dec ); p_sys->p_startcode[0] = 0; p_sys->p_startcode[1] = 0; p_sys->p_startcode[2] = 1; p_sys->i_offset = 0; p_sys->p_seq = NULL; p_sys->p_ext = NULL; p_sys->p_frame = NULL; p_sys->pp_last = &p_sys->p_frame; p_sys->b_frame_slice = VLC_FALSE; p_sys->i_dts = p_sys->i_pts = 0; p_sys->i_frame_rate = 1; p_sys->i_frame_rate_base = 1; p_sys->b_seq_progressive = VLC_TRUE; p_sys->b_low_delay = VLC_TRUE; p_sys->i_seq_old = 0; p_sys->i_temporal_ref = 0; p_sys->i_picture_type = 0; p_sys->i_picture_structure = 0x03; /* frame */ p_sys->i_top_field_first = 0; p_sys->i_repeat_first_field = 0; p_sys->i_progressive_frame = 0; p_sys->b_inited = 0; p_sys->i_interpolated_dts = 0; p_sys->i_old_duration = 0; p_sys->i_last_ref_pts = 0; return VLC_SUCCESS; }
/***************************************************************************** * OpenCommon: probe the decoder/packetizer and return score *****************************************************************************/ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; vlc_fourcc_t i_codec; switch( p_dec->fmt_in.i_codec ) { case VLC_CODEC_A52: i_codec = VLC_CODEC_A52; break; case VLC_CODEC_EAC3: /* XXX ugly hack, a52 does not support eac3 so no eac3 pass-through * support */ if( !b_packetizer ) return VLC_EGENERIC; i_codec = VLC_CODEC_EAC3; break; default: return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) return VLC_ENOMEM; /* Misc init */ p_sys->b_packetizer = b_packetizer; p_sys->i_state = STATE_NOSYNC; date_Set( &p_sys->end_date, 0 ); p_sys->i_pts = VLC_TS_INVALID; block_BytestreamInit( &p_sys->bytestream ); /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; p_dec->fmt_out.i_codec = i_codec; p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */ p_dec->fmt_out.audio.i_bytes_per_frame = 0; /* Set callback */ if( b_packetizer ) p_dec->pf_packetize = (block_t *(*)(decoder_t *, block_t **)) DecodeBlock; else p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **)) DecodeBlock; return VLC_SUCCESS; }
static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; switch( p_dec->fmt_in.i_codec ) { case VLC_CODEC_EAC3: case VLC_CODEC_A52: break; default: return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) return VLC_ENOMEM; /* Misc init */ p_sys->i_state = STATE_NOSYNC; date_Set( &p_sys->end_date, 0 ); p_sys->i_pts = VLC_TS_INVALID; p_sys->b_date_set = false; p_sys->b_discontuinity = false; block_BytestreamInit( &p_sys->bytestream ); /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_out.audio = p_dec->fmt_in.audio; p_sys->frame.b_eac3 = false; p_sys->frame.i_rate = p_dec->fmt_out.audio.i_rate; p_sys->frame.i_channels = p_dec->fmt_out.audio.i_channels; p_sys->frame.i_size = p_dec->fmt_out.audio.i_bytes_per_frame; p_sys->frame.i_samples = p_dec->fmt_out.audio.i_frame_length; p_sys->frame.i_channels_conf = p_dec->fmt_out.audio.i_original_channels; p_sys->frame.i_bitrate = p_dec->fmt_out.i_bitrate; /* Set callback */ p_dec->pf_packetize = PacketizeBlock; p_dec->pf_flush = PacketizeFlush; return VLC_SUCCESS; }
static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; switch( p_dec->fmt_in.i_codec ) { case VLC_CODEC_EAC3: case VLC_CODEC_A52: break; default: return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) return VLC_ENOMEM; /* Misc init */ p_sys->i_state = STATE_NOSYNC; date_Set( &p_sys->end_date, 0 ); p_sys->i_pts = VLC_TS_INVALID; p_sys->b_date_set = false; p_sys->b_discontuinity = false; memset(&p_sys->frame, 0, sizeof(vlc_a52_header_t)); block_BytestreamInit( &p_sys->bytestream ); /* Set output properties (Passthrough ONLY) */ p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_out.audio = p_dec->fmt_in.audio; /* Set callback */ p_dec->pf_packetize = PacketizeBlock; p_dec->pf_flush = PacketizeFlush; return VLC_SUCCESS; }
/***************************************************************************** * Open: probe the packetizer and return score * When opening after demux, the packetizer is only loaded AFTER the decoder * That means that what you set in fmt_out is ignored by the decoder in this special case *****************************************************************************/ static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'h', '2', '6', '4') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'H', '2', '6', '4') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'V', 'S', 'S', 'H') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'v', 's', 's', 'h') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'D', 'A', 'V', 'C') && ( p_dec->fmt_in.i_codec != VLC_FOURCC( 'a', 'v', 'c', '1') || p_dec->fmt_in.i_extra < 7 ) ) { return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = malloc( sizeof(decoder_sys_t) ) ) == NULL ) { msg_Err( p_dec, "out of memory" ); return VLC_EGENERIC; } p_sys->i_state = STATE_NOSYNC; p_sys->i_offset = 0; p_sys->startcode[0] = 0; p_sys->startcode[1] = 0; p_sys->startcode[2] = 0; p_sys->startcode[3] = 1; p_sys->bytestream = block_BytestreamInit( p_dec ); p_sys->b_slice = VLC_FALSE; p_sys->p_frame = NULL; p_sys->b_sps = VLC_FALSE; p_sys->b_pps = VLC_FALSE; p_sys->p_sps = 0; p_sys->p_pps = 0; p_sys->b_header= VLC_FALSE; p_sys->slice.i_nal_type = -1; p_sys->slice.i_nal_ref_idc = -1; p_sys->slice.i_idr_pic_id = -1; p_sys->slice.i_frame_num = -1; p_sys->slice.i_frame_type = 0; p_sys->slice.i_pic_parameter_set_id = -1; p_sys->slice.i_field_pic_flag = 0; p_sys->slice.i_bottom_field_flag = -1; p_sys->slice.i_pic_order_cnt_lsb = -1; p_sys->slice.i_delta_pic_order_cnt_bottom = -1; /* Setup properties */ es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); p_dec->fmt_out.i_codec = VLC_FOURCC( 'h', '2', '6', '4' ); if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'v', 'c', '1' ) ) { /* This type of stream is produced by mp4 and matroska * when we want to store it in another streamformat, you need to convert * The fmt_in.p_extra should ALWAYS contain the avcC * The fmt_out.p_extra should contain all the SPS and PPS with 4 byte startcodes */ uint8_t *p = &((uint8_t*)p_dec->fmt_in.p_extra)[4]; int i_sps, i_pps; int i; /* Parse avcC */ p_sys->i_avcC_length_size = 1 + ((*p++)&0x03); /* Read SPS */ i_sps = (*p++)&0x1f; for( i = 0; i < i_sps; i++ ) { int i_length = GetWBE( p ); block_t *p_sps = nal_get_annexeb( p_dec, p + 2, i_length ); p_sys->p_sps = block_Duplicate( p_sps ); p_sps->i_pts = p_sps->i_dts = mdate(); ParseNALBlock( p_dec, p_sps ); p += 2 + i_length; } /* Read PPS */ i_pps = *p++; for( i = 0; i < i_pps; i++ ) { int i_length = GetWBE( p ); block_t *p_pps = nal_get_annexeb( p_dec, p + 2, i_length ); p_sys->p_pps = block_Duplicate( p_pps ); p_pps->i_pts = p_pps->i_dts = mdate(); ParseNALBlock( p_dec, p_pps ); p += 2 + i_length; } msg_Dbg( p_dec, "avcC length size=%d, sps=%d, pps=%d", p_sys->i_avcC_length_size, i_sps, i_pps ); /* FIXME: FFMPEG isn't happy at all if you leave this */ if( p_dec->fmt_out.i_extra ) free( p_dec->fmt_out.p_extra ); p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = NULL; /* Set the new extradata */ p_dec->fmt_out.i_extra = p_sys->p_pps->i_buffer + p_sys->p_sps->i_buffer; p_dec->fmt_out.p_extra = (uint8_t*)malloc( p_dec->fmt_out.i_extra ); memcpy( (uint8_t*)p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer); memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer); p_sys->b_header = VLC_TRUE; /* Set callback */ p_dec->pf_packetize = PacketizeAVC1; } else { /* This type of stream contains data with 3 of 4 byte startcodes * The fmt_in.p_extra MAY contain SPS/PPS with 4 byte startcodes * The fmt_out.p_extra should be the same */ /* Set callback */ p_dec->pf_packetize = Packetize; /* */ if( p_dec->fmt_in.i_extra > 0 ) { block_t *p_init = block_New( p_dec, p_dec->fmt_in.i_extra ); block_t *p_pic; memcpy( p_init->p_buffer, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra ); while( ( p_pic = Packetize( p_dec, &p_init ) ) ) { /* Should not occur because we should only receive SPS/PPS */ block_Release( p_pic ); } } } return VLC_SUCCESS; }
/***************************************************************************** * Open: probe the packetizer and return score *****************************************************************************/ static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_CODEC_DIRAC ) return VLC_EGENERIC; p_dec->pf_packetize = Packetize; /* Create the output format */ es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); p_dec->p_sys = p_sys = calloc( 1, sizeof( decoder_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_sys->i_eu_pts = p_sys->i_eu_dts = VLC_TS_INVALID; p_sys->i_sync_pts = p_sys->i_sync_dts = VLC_TS_INVALID; p_sys->i_dts_last_out = p_sys->i_pts_last_out = VLC_TS_INVALID; p_sys->i_state = NOT_SYNCED; block_BytestreamInit( &p_sys->bytestream ); p_sys->pp_outqueue_last = &p_sys->p_outqueue; p_sys->pp_eu_last = &p_sys->p_eu; date_Init( &p_sys->dts, 1, 1 ); dirac_ReorderInit( &p_sys->reorder_buf ); if( p_dec->fmt_in.i_extra > 0 ) { /* handle hacky systems like ogg that dump some headers * in p_extra. and packetizers that expect it to be filled * in before real startup */ block_t *p_init = block_Alloc( p_dec->fmt_in.i_extra ); if( !p_init ) { /* memory might be avaliable soon. it isn't the end of * the world that fmt_in.i_extra isn't handled */ return VLC_SUCCESS; } memcpy( p_init->p_buffer, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra ); /* in theory p_extra should contain just a seqhdr&EOS. if just a * seqhdr, ensure it is extracted by appending an EOS with * prev_offset = seqhdr length, ie i_extra. If all were actually * ok, this won't do anything bad */ if( ( p_init->p_next = dirac_EmitEOS( p_dec, p_dec->fmt_in.i_extra ) ) ) { /* to ensure that one of these two EOS dataunits gets extracted, * send a second one */ p_init->p_next->p_next = dirac_EmitEOS( p_dec, 13 ); } block_t *p_block; while( ( p_block = Packetize( p_dec, &p_init ) ) ) block_Release( p_block ); } return VLC_SUCCESS; }
/***************************************************************************** * Open: probe the packetizer and return score *****************************************************************************/ static int Open( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'h', '2', '6', '4') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'H', '2', '6', '4') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'V', 'S', 'S', 'H') && p_dec->fmt_in.i_codec != VLC_FOURCC( 'v', 's', 's', 'h') && ( p_dec->fmt_in.i_codec != VLC_FOURCC( 'a', 'v', 'c', '1') || p_dec->fmt_in.i_extra < 7 ) ) { return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = malloc( sizeof(decoder_sys_t) ) ) == NULL ) { msg_Err( p_dec, "out of memory" ); return VLC_EGENERIC; } p_sys->i_state = STATE_NOSYNC; p_sys->i_offset = 0; p_sys->startcode[0] = 0; p_sys->startcode[1] = 0; p_sys->startcode[2] = 0; p_sys->startcode[3] = 1; p_sys->bytestream = block_BytestreamInit( p_dec ); p_sys->b_slice = VLC_FALSE; p_sys->p_frame = NULL; p_sys->i_dts = 0; p_sys->i_pts = 0; p_sys->i_flags = 0; p_sys->b_sps = VLC_FALSE; p_sys->i_nal_type = -1; p_sys->i_nal_ref_idc = -1; p_sys->i_idr_pic_id = -1; p_sys->i_frame_num = -1; /* Setup properties */ es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); p_dec->fmt_out.i_codec = VLC_FOURCC( 'h', '2', '6', '4' ); /* FIXME: FFMPEG isn't happy at all if you leave this */ if( p_dec->fmt_out.i_extra ) free( p_dec->fmt_out.p_extra ); p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = 0; if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'v', 'c', '1' ) ) { uint8_t *p = &((uint8_t*)p_dec->fmt_in.p_extra)[4]; int i_sps, i_pps; int i; /* Parse avcC */ p_sys->i_avcC_length_size = 1 + ((*p++)&0x03); /* Read SPS */ i_sps = (*p++)&0x1f; for( i = 0; i < i_sps; i++ ) { int i_length = GetWBE( p ); block_t *p_sps = nal_get_annexeb( p_dec, p + 2, i_length ); ParseNALBlock( p_dec, p_sps ); p += 2 + i_length; } /* Read PPS */ i_pps = *p++; for( i = 0; i < i_pps; i++ ) { int i_length = GetWBE( p ); block_t *p_pps = nal_get_annexeb( p_dec, p + 2, i_length ); ParseNALBlock( p_dec, p_pps ); p += 2 + i_length; } msg_Dbg( p_dec, "avcC length size=%d sps=%d pps=%d", p_sys->i_avcC_length_size, i_sps, i_pps ); /* Set callback */ p_dec->pf_packetize = PacketizeAVC1; } else { /* Set callback */ p_dec->pf_packetize = Packetize; } return VLC_SUCCESS; }