static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, video_format_t *p_fmt_in, video_format_t *p_fmt_out ) { block_t *p_block; picture_t *p_pic; stream_t *p_stream = NULL; uint64_t i_size; p_stream = vlc_stream_NewMRL( p_image->p_parent, psz_url ); if( !p_stream ) { msg_Dbg( p_image->p_parent, "could not open %s for reading", psz_url ); return NULL; } if( vlc_stream_GetSize( p_stream, &i_size ) || i_size > SSIZE_MAX ) { msg_Dbg( p_image->p_parent, "could not read %s", psz_url ); goto error; } p_block = vlc_stream_Block( p_stream, i_size ); if( p_block == NULL ) goto error; if( !p_fmt_in->i_chroma ) { char *psz_mime = stream_ContentType( p_stream ); if( psz_mime != NULL ) { p_fmt_in->i_chroma = image_Mime2Fourcc( psz_mime ); free( psz_mime ); } } vlc_stream_Delete( p_stream ); if( !p_fmt_in->i_chroma ) { /* Try to guess format from file name */ p_fmt_in->i_chroma = image_Ext2Fourcc( psz_url ); } p_pic = ImageRead( p_image, p_block, p_fmt_in, p_fmt_out ); return p_pic; error: vlc_stream_Delete( p_stream ); return NULL; }
/** * Checks stream Content-Type against a known one */ bool CheckContentType( stream_t * p_stream, const char * psz_ctype ) { char *psz_check = stream_ContentType( p_stream ); if( !psz_check ) return false; int i_len = strlen( psz_check ); if ( i_len == 0 ) { free( psz_check ); return false; } /* check for Content-Type: foo-type; charset=... */ const char * psz_sep = strchr( psz_check, ';' ); if ( psz_sep ) i_len = __MIN( i_len, psz_sep - psz_check ); int i_res = strncasecmp( psz_check, psz_ctype, i_len ); free( psz_check ); return ( i_res == 0 ) ? true : false; }
/***************************************************************************** * Open: check file and initializes structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; int i_size; bool b_matched = false; if( IsMxpeg( p_demux->s ) && !p_demux->b_force ) // let avformat handle this case return VLC_EGENERIC; demux_sys_t *p_sys = (demux_sys_t *)malloc( sizeof( demux_sys_t ) ); // sunqueen modify if( unlikely(p_sys == NULL) ) return VLC_ENOMEM; p_demux->pf_control = Control; p_demux->p_sys = p_sys; p_sys->p_es = NULL; p_sys->i_time = VLC_TS_0; p_sys->i_level = 0; p_sys->psz_separator = NULL; p_sys->i_frame_size_estimate = 15 * 1024; char *content_type = stream_ContentType( p_demux->s ); if ( content_type ) { //FIXME: this is not fully match to RFC char* boundary = strstr( content_type, "boundary=" ); if( boundary ) { boundary += strlen( "boundary=" ); size_t len = strlen( boundary ); if( len > 2 && boundary[0] == '"' && boundary[len-1] == '"' ) { boundary[len-1] = '\0'; boundary++; } p_sys->psz_separator = strdup( boundary ); if( !p_sys->psz_separator ) { free( content_type ); goto error; } } free( content_type ); } b_matched = CheckMimeHeader( p_demux, &i_size); if( b_matched ) { p_demux->pf_demux = MimeDemux; stream_Read( p_demux->s, NULL, i_size ); } else if( i_size == 0 ) { /* 0xffd8 identify a JPEG SOI */ if( p_sys->p_peek[0] == 0xFF && p_sys->p_peek[1] == 0xD8 ) { msg_Dbg( p_demux, "JPEG SOI marker detected" ); p_demux->pf_demux = MjpgDemux; p_sys->i_level++; } else { goto error; } } else { goto error; } /* Frame rate */ float f_fps = var_InheritFloat( p_demux, "mjpeg-fps" ); p_sys->i_still_end = 0; if( demux_IsPathExtension( p_demux, ".jpeg" ) || demux_IsPathExtension( p_demux, ".jpg" ) ) { /* Plain JPEG file = single still picture */ p_sys->b_still = true; if( f_fps == 0.f ) /* Defaults to 1fps */ f_fps = 1.f; } else p_sys->b_still = false; p_sys->i_frame_length = f_fps ? (CLOCK_FREQ / f_fps) : 0; es_format_Init( &p_sys->fmt, VIDEO_ES, 0 ); p_sys->fmt.i_codec = VLC_CODEC_MJPG; p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt ); return VLC_SUCCESS; error: free( p_sys->psz_separator ); free( p_sys ); 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 ) { char *psz_mime = stream_ContentType( p_demux->s ); if ( !psz_mime || strcmp( psz_mime, "audio/flac" ) ) { free( psz_mime ); return VLC_EGENERIC; } free( psz_mime ); } /* 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; p_sys->i_length = 0; p_sys->i_pts = 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 */ 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 ); } return VLC_SUCCESS; }