/***************************************************************************** * Open: initializes demux structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; bool b_forced = false; const uint8_t *p_peek; es_format_t fmt; if( vlc_stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) { msg_Dbg( p_demux, "cannot peek" ); return VLC_EGENERIC; } if( p_demux->obj.force ) b_forced = true; if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 ) { if( !b_forced ) return VLC_EGENERIC; msg_Err( p_demux, "this doesn't look like an MPEG ES stream, continuing" ); } if( p_peek[3] > 0xb9 ) { if( !b_forced ) return VLC_EGENERIC; msg_Err( p_demux, "this seems to be a system stream (PS plug-in ?), but continuing" ); } p_demux->pf_demux = Demux; p_demux->pf_control= Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); p_sys->b_start = true; p_sys->p_es = NULL; /* Load the mpegvideo packetizer */ es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_MPGV ); p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "mpeg video" ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } /* create the output */ p_sys->p_es = es_out_Add( p_demux->out, &fmt ); if( p_sys->p_es == NULL ) { Close( p_this ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * Open: initializes demux structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; es_format_t fmt; if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC; if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 || p_peek[3] != 0x0f ) /* Sequence header */ { if( !p_demux->b_force ) { msg_Warn( p_demux, "vc-1 module discarded (no startcode)" ); return VLC_EGENERIC; } msg_Err( p_demux, "this doesn't look like a VC-1 ES stream, " "continuing anyway" ); } p_sys = (demux_sys_t *)malloc( sizeof( demux_sys_t ) ); // sunqueen modify if( unlikely(p_sys == NULL) ) return VLC_ENOMEM; p_demux->pf_demux = Demux; p_demux->pf_control= Control; p_demux->p_sys = p_sys; p_sys->p_es = NULL; p_sys->i_dts = 0; p_sys->f_fps = var_CreateGetFloat( p_demux, "vc1-fps" ); if( p_sys->f_fps < 0.001 ) p_sys->f_fps = 0.0; /* Load the packetizer */ es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_VC1 ); p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "VC-1" ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * Open: initializes demux structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; es_format_t fmt; if( stream_Peek( p_demux->s, &p_peek, 5 ) < 5 ) return VLC_EGENERIC; if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x00 || p_peek[3] != 0x01 || (p_peek[4]&0x1F) != 7 ) /* SPS */ { if( !p_demux->b_force ) { msg_Warn( p_demux, "h264 module discarded (no startcode)" ); return VLC_EGENERIC; } msg_Err( p_demux, "this doesn't look like a H264 ES stream, " "continuing anyway" ); } p_demux->pf_demux = Demux; p_demux->pf_control= Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); p_sys->p_es = NULL; p_sys->i_dts = 0; p_sys->f_fps = var_CreateGetFloat( p_demux, "h264-fps" ); if( p_sys->f_fps < 0.001f ) p_sys->f_fps = 0.001f; msg_Dbg( p_demux, "using %.2f fps", (double) p_sys->f_fps ); /* Load the mpegvideo packetizer */ es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_H264 ); p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "h264" ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * Open: initializes demux structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; es_format_t fmt; if( stream_Peek( p_demux->s, &p_peek, 5 ) < 5 ) return VLC_EGENERIC; if( p_peek[0] != 'B' || p_peek[1] != 'B' || p_peek[2] != 'C' || p_peek[3] != 'D') /* start of ParseInfo */ { if( !p_demux->b_force ) return VLC_EGENERIC; msg_Err( p_demux, "This doesn't look like a Dirac stream (incorrect parsecode)" ); msg_Warn( p_demux, "continuing anyway" ); } p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = (demux_sys_t *)calloc( 1, sizeof( demux_sys_t ) ); // sunqueen modify if( !p_sys ) return VLC_ENOMEM; p_sys->i_pts_offset_lowtide = INT64_MAX; p_sys->i_state = DIRAC_DEMUX_FIRST; p_sys->i_dtsoffset = var_CreateGetInteger( p_demux, DEMUX_CFG_PREFIX DEMUX_DTSOFFSET ); /* Load the packetizer */ es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_DIRAC ); p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "dirac" ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * Open: initializes demux structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; es_format_t fmt; if( stream_Peek( p_demux->s, &p_peek, 5 ) < 5 ) return VLC_EGENERIC; if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x00 || p_peek[3] != 0x01 || (p_peek[4]&0xFE) != 0x40 ) /* VPS & forbidden zero bit*/ { if( !p_demux->b_force ) { msg_Warn( p_demux, "hevc module discarded (no startcode)" ); return VLC_EGENERIC; } msg_Err( p_demux, "this doesn't look like a HEVC ES stream, " "continuing anyway" ); } p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); if( !p_demux->p_sys ) return VLC_ENOMEM; p_sys->p_es = NULL; p_sys->i_dts = VLC_TS_0; p_sys->f_force_fps = var_CreateGetFloat( p_demux, "hevc-force-fps" ); if( p_sys->f_force_fps != 0.0f ) { p_sys->f_fps = ( p_sys->f_force_fps < 0.001f )? 0.001f: p_sys->f_force_fps; msg_Dbg( p_demux, "using %.2f fps", (double) p_sys->f_fps ); } else p_sys->f_fps = 0.0f; /* Load the hevc packetizer */ es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_HEVC ); p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "hevc" ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } p_sys->p_packetizer->fmt_out.b_packetized = true; p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out); if( !p_sys->p_es ) { demux_PacketizerDestroy( p_sys->p_packetizer ); free( p_sys ); return VLC_ENOMEM; } p_demux->pf_demux = Demux; p_demux->pf_control= Control; return VLC_SUCCESS; }
/***************************************************************************** * Open: initializes ES structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; es_format_t fmt; /* Have a peep at the show. */ if( vlc_stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC; if( p_peek[0]!='f' || p_peek[1]!='L' || p_peek[2]!='a' || p_peek[3]!='C' ) { if( !p_demux->obj.force && !demux_IsContentType( p_demux, "audio/flac" ) ) return VLC_EGENERIC; /* User forced */ msg_Err( p_demux, "this doesn't look like a flac stream, " "continuing anyway" ); } p_sys = malloc( sizeof( demux_sys_t ) ); if( unlikely(p_sys == NULL) ) return VLC_ENOMEM; p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys; p_sys->b_start = true; p_sys->i_next_block_flags = 0; p_sys->p_packetizer = NULL; p_sys->p_meta = NULL; p_sys->i_length = 0; p_sys->i_pts = VLC_TS_INVALID; p_sys->p_es = NULL; p_sys->p_current_block = NULL; TAB_INIT( p_sys->i_seekpoint, p_sys->seekpoint ); TAB_INIT( p_sys->i_attachments, p_sys->attachments); TAB_INIT( p_sys->i_title_seekpoints, p_sys->pp_title_seekpoints ); p_sys->i_cover_idx = 0; p_sys->i_cover_score = 0; es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_FLAC ); /* We need to read and store the STREAMINFO metadata into fmt extra */ if( ParseHeaders( p_demux, &fmt ) ) goto error; /* Load the FLAC packetizer */ p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "flac" ); if( !p_sys->p_packetizer ) goto error; if( p_sys->i_cover_idx < p_sys->i_attachments ) { char psz_url[128]; if( !p_sys->p_meta ) p_sys->p_meta = vlc_meta_New(); snprintf( psz_url, sizeof(psz_url), "attachment://%s", p_sys->attachments[p_sys->i_cover_idx]->psz_name ); vlc_meta_Set( p_sys->p_meta, vlc_meta_ArtworkURL, psz_url ); } p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); if( !p_sys->p_es ) goto error; return VLC_SUCCESS; error: Close( p_this ); return VLC_EGENERIC; }
/***************************************************************************** * Open: initializes ES structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; const uint8_t *p_peek; uint8_t *p_streaminfo; int i_streaminfo; es_format_t fmt; /* Have a peep at the show. */ if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC; if( p_peek[0]!='f' || p_peek[1]!='L' || p_peek[2]!='a' || p_peek[3]!='C' ) { if( !p_demux->b_force ) return VLC_EGENERIC; /* User forced */ msg_Err( p_demux, "this doesn't look like a flac stream, " "continuing anyway" ); } p_sys = malloc( sizeof( demux_sys_t ) ); if( unlikely(p_sys == NULL) ) return VLC_ENOMEM; p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys; p_sys->b_start = true; p_sys->p_meta = NULL; memset( &p_sys->replay_gain, 0, sizeof(p_sys->replay_gain) ); p_sys->i_length = 0; p_sys->i_time_offset = 0; p_sys->i_pts = 0; p_sys->i_pts_start = 0; p_sys->p_es = NULL; TAB_INIT( p_sys->i_seekpoint, p_sys->seekpoint ); TAB_INIT( p_sys->i_attachments, p_sys->attachments); p_sys->i_cover_idx = 0; p_sys->i_cover_score = 0; /* We need to read and store the STREAMINFO metadata */ if( ReadMeta( p_demux, &p_streaminfo, &i_streaminfo ) ) { free( p_sys ); return VLC_EGENERIC; } /* Load the FLAC packetizer */ /* Store STREAMINFO for the decoder and packetizer */ p_streaminfo[4] |= 0x80; /* Fake this as the last metadata block */ es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_FLAC ); fmt.i_extra = i_streaminfo; fmt.p_extra = p_streaminfo; p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "flac" ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } if( p_sys->i_cover_idx < p_sys->i_attachments ) { char psz_url[128]; if( !p_sys->p_meta ) p_sys->p_meta = vlc_meta_New(); snprintf( psz_url, sizeof(psz_url), "attachment://%s", p_sys->attachments[p_sys->i_cover_idx]->psz_name ); vlc_meta_Set( p_sys->p_meta, vlc_meta_ArtworkURL, psz_url ); } vlc_audio_replay_gain_MergeFromMeta( &p_sys->replay_gain, p_sys->p_meta ); return VLC_SUCCESS; }
static int GenericOpen( demux_t *p_demux, const char *psz_module, vlc_fourcc_t i_codec, int(*pf_probe)(const uint8_t *, size_t, void *), void *p_ctx, const char **pp_psz_exts, const char **pp_psz_mimes ) { demux_sys_t *p_sys; const uint8_t *p_peek; es_format_t fmt; uint8_t annexb_startcode[] = {0,0,0,1}; int i_ret = 0; /* Restrict by type first */ if( !p_demux->obj.force && !check_Property( p_demux, pp_psz_exts, demux_IsPathExtension ) && !check_Property( p_demux, pp_psz_mimes, demux_IsContentType ) ) { return VLC_EGENERIC; } /* First check for first AnnexB header */ if( vlc_stream_Peek( p_demux->s, &p_peek, H26X_MIN_PEEK ) == H26X_MIN_PEEK && !memcmp( p_peek, annexb_startcode, 4 ) ) { size_t i_peek = H26X_MIN_PEEK; size_t i_peek_target = H26X_MIN_PEEK; size_t i_probe_offset = 4; const uint8_t *p_probe = p_peek; bool b_synced = true; unsigned i_bitflow = 0; for( unsigned i=0; i<H26X_NAL_COUNT; i++ ) { while( !b_synced ) { if( i_probe_offset + H26X_MIN_PEEK >= i_peek && i_peek_target + H26X_PEEK_CHUNK <= H26X_MAX_PEEK ) { i_peek_target += H26X_PEEK_CHUNK; i_peek = vlc_stream_Peek( p_demux->s, &p_peek, i_peek_target ); } if( i_probe_offset + H26X_MIN_PEEK >= i_peek ) break; p_probe = &p_peek[i_probe_offset]; i_bitflow = (i_bitflow << 1) | (!p_probe[0]); /* Check for annexB */ if( p_probe[0] == 0x01 && ((i_bitflow & 0x06) == 0x06) ) b_synced = true; i_probe_offset++; } if( b_synced ) { p_probe = &p_peek[i_probe_offset]; i_ret = pf_probe( p_probe, i_peek - i_probe_offset, p_ctx ); } if( i_ret != 0 ) break; i_probe_offset += 4; b_synced = false; } } if( i_ret < 1 ) { if( !p_demux->obj.force ) { msg_Warn( p_demux, "%s module discarded (no startcode)", psz_module ); return VLC_EGENERIC; } msg_Err( p_demux, "this doesn't look like a %s ES stream, " "continuing anyway", psz_module ); } p_demux->pf_demux = Demux; p_demux->pf_control= Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); p_sys->p_es = NULL; p_sys->frame_rate_num = 0; p_sys->frame_rate_den = 0; float f_fps = 0; char *psz_fpsvar; if( asprintf( &psz_fpsvar, "%s-fps", psz_module ) ) { f_fps = var_CreateGetFloat( p_demux, psz_fpsvar ); free( psz_fpsvar ); } if( f_fps ) { if ( f_fps < 0.001f ) f_fps = 0.001f; p_sys->frame_rate_den = 1000; p_sys->frame_rate_num = 1000 * f_fps; date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den ); } else date_Init( &p_sys->dts, 25000, 1000 ); date_Set( &p_sys->dts, VLC_TICK_0 ); /* Load the mpegvideo packetizer */ es_format_Init( &fmt, VIDEO_ES, i_codec ); if( f_fps ) { fmt.video.i_frame_rate = p_sys->dts.i_divider_num; fmt.video.i_frame_rate_base = p_sys->dts.i_divider_den; } p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, psz_module ); if( !p_sys->p_packetizer ) { free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS; }