Exemplo n.º 1
0
char * read_page(char * url)
{
    URL_FILE * page = url_fopen(url, "rb");

    if (page == NULL)
        return NULL;

    char * result = (char *)malloc(1024 * 1024);

    if (result == NULL)
    {
        url_fclose(page);
        return NULL;
    }

    result[0] = '\0';

    if (page != NULL)
    {
        char buffer[8];
        int n = 0;

        n = url_fread(buffer, 1, 8, page);

        while(n > 0)
        {
            strncat(result, buffer, n);
            n = url_fread(buffer, 1, 8, page);
        }
    }

    url_fclose(page);

    return result;
}
Exemplo n.º 2
0
void CFFMPEGLoader::Delete() {
    for(UINT i=0; i<FFMPEG_PACKET_MAX_SIZE; i++) {
        if(pktLastAudio[i].data)
            av_free_packet(&pktLastAudio[i]);
        if(pktLastVideo[i].data)
            av_free_packet(&pktLastVideo[i]);
    }
    if (pVideoStream)
        avcodec_close(pVideoStream->codec);
    if (pAudioStream)
        avcodec_close(pAudioStream->codec);
    if(pFrameRGB!=NULL)
        av_free(pFrameRGB);
    if(pFrame!=NULL)
        av_free(pFrame);
    if(pVCodecCon!=NULL)
        avcodec_close(pVCodecCon);
    if(pFormatCon!=NULL) {
        if(!bOutput)
            av_close_input_file(pFormatCon);
        else {
            if (!(pFormatCon->oformat->flags & AVFMT_NOFILE)) {
                /* close the output file */
#ifndef WIN32
                url_fclose(pFormatCon->pb);
#else
                url_fclose(&pFormatCon->pb);
#endif
            }
            av_free(pFormatCon);
        }
    }
}
Exemplo n.º 3
0
/*
 * Import data into GPDB.
 */
Datum
gphdfsprotocol_import(PG_FUNCTION_ARGS)
{
	char     *data;
	int	      datlen;
	size_t    nread = 0;
	gphdfs_import_t *myData;

	/* Must be called via the external table format manager */
	if (!CALLED_AS_EXTPROTOCOL(fcinfo))
		elog(ERROR, "cannot execute gphdfsprotocol_import outside protocol manager");

	/* Get our internal description of the protocol */
	myData = (gphdfs_import_t*) EXTPROTOCOL_GET_USER_CTX(fcinfo);

	/* =======================================================================
	 *                            DO LAST CALL
	 *                            Nothing to be done if it has already been closed
	 * ======================================================================= */
	if (EXTPROTOCOL_IS_LAST_CALL(fcinfo))
	{
		if (myData != NULL && !myData->importDone)
			url_fclose(myData->importFile, false, "gphdfs protocol");
		PG_RETURN_INT32(0);
	}

	/* =======================================================================
	 *                            DO OPEN
	 * ======================================================================= */
	if (myData == NULL)
	{
		myData = palloc(sizeof(gphdfs_import_t));
		myData->importFile = gphdfs_fopen(fcinfo, false);
		myData->importDone = false;
		EXTPROTOCOL_SET_USER_CTX(fcinfo, myData);
	}

	/* =======================================================================
	 *                            DO THE IMPORT
	 * ======================================================================= */
	data 	= EXTPROTOCOL_GET_DATABUF(fcinfo);
	datlen 	= EXTPROTOCOL_GET_DATALEN(fcinfo);

	if (datlen > 0 && !myData->importDone)
		nread = url_execute_fread(data, datlen, myData->importFile, NULL);

	/* =======================================================================
	 *                            DO CLOSE
	 *                            close early to raise error early
	 * ======================================================================= */
	if (nread == 0)
	{
		myData->importDone = true;
		url_fclose(myData->importFile, true, "gphdfs protocol");
	}

	PG_RETURN_INT32((int)nread);
}
Exemplo n.º 4
0
Arquivo: yuv.c Projeto: VoxOx/VoxOx
static int yuv_read(ByteIOContext *f,
                    int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
{
    ByteIOContext pb1, *pb = &pb1;
    int img_size, ret;
    char fname[1024], *p;
    int size;
    URLContext *h;
    AVImageInfo info1, *info = &info1;

    img_size = url_fsize(f);

    /* XXX: hack hack */
    h = url_fileno(f);
    url_get_filename(h, fname, sizeof(fname));

    if (infer_size(&info->width, &info->height, img_size) < 0) {
        return AVERROR_IO;
    }
    info->pix_fmt = PIX_FMT_YUV420P;

    ret = alloc_cb(opaque, info);
    if (ret)
        return ret;

    size = info->width * info->height;

    p = strrchr(fname, '.');
    if (!p || p[1] != 'Y')
        return AVERROR_IO;

    get_buffer(f, info->pict.data[0], size);

    p[1] = 'U';
    if (url_fopen(pb, fname, URL_RDONLY) < 0)
        return AVERROR_IO;

    get_buffer(pb, info->pict.data[1], size / 4);
    url_fclose(pb);

    p[1] = 'V';
    if (url_fopen(pb, fname, URL_RDONLY) < 0)
        return AVERROR_IO;

    get_buffer(pb, info->pict.data[2], size / 4);
    url_fclose(pb);
    return 0;
}
Exemplo n.º 5
0
/*=======================================================================================*/
int url_is_file_list(ByteIOContext *s, const char *filename)
{
    int ret;
    list_demux_t *demux;
    ByteIOContext *lio = s;
    int64_t    *oldpos = 0;
    if (am_getconfig_bool("media.amplayer.usedm3udemux")) {
        return 0;    /*if used m3u demux,always failed;*/
    }
    if (!lio) {
        ret = url_fopen(&lio, filename, AVIO_FLAG_READ | URL_MINI_BUFFER|URL_NO_LP_BUFFER);
        if (ret != 0) {
            return AVERROR(EIO);
        }
    } else {
        oldpos = url_ftell(lio);
    }
    demux = probe_demux(lio, filename);
    if (lio != s) {
        url_fclose(lio);
    } else {
        url_fseek(lio, oldpos, SEEK_SET);
    }
    return demux != NULL ? 100 : 0;
}
Exemplo n.º 6
0
    ~impl() {
        if (swsCtx)
            sws_freeContext(swsCtx);

        if (codecCtx)
            avcodec_close(codecCtx);

        if (buffer0)
            av_free(buffer0);
        if (frame0)
            av_free(frame0);
        if (buffer1)
            av_free(buffer1);
        if (frame1)
            av_free(frame1);
        if (output_buffer)
            av_free(output_buffer);

        if (formatCtx) {
            for(unsigned i = 0; i < formatCtx->nb_streams; i++) {
                av_freep(&formatCtx->streams[i]->codec);
                av_freep(&formatCtx->streams[i]);
            }

            if (formatCtx->pb) {
                #if LIBAVFORMAT_VERSION_MAJOR >= 54
                    avio_close(formatCtx->pb);
                #else
                    url_fclose(formatCtx->pb);
                #endif
            }

            av_free(formatCtx);
        }
    }
Exemplo n.º 7
0
static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
    VideoData *s = s1->priv_data;
    char filename[1024];
    int i;
    int size[3]={0}, ret[3]={0};
    ByteIOContext f1[3], *f[3]= {&f1[0], &f1[1], &f1[2]};
    AVCodecContext *codec= s1->streams[0]->codec;

    if (!s->is_pipe) {
        /* loop over input */
        if (s1->loop_input && s->img_number > s->img_last) {
            s->img_number = s->img_first;
        }
        if (av_get_frame_filename(filename, sizeof(filename),
                                  s->path, s->img_number)<0 && s->img_number > 1)
            return AVERROR_IO;
        for(i=0; i<3; i++){
            if (url_fopen(f[i], filename, URL_RDONLY) < 0)
                return AVERROR_IO;
            size[i]= url_fsize(f[i]);

            if(codec->codec_id != CODEC_ID_RAWVIDEO)
                break;
            filename[ strlen(filename) - 1 ]= 'U' + i;
        }

        if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
            infer_size(&codec->width, &codec->height, size[0]);
    } else {
        f[0] = &s1->pb;
        if (url_feof(f[0]))
            return AVERROR_IO;
        size[0]= 4096;
    }

    av_new_packet(pkt, size[0] + size[1] + size[2]);
    pkt->stream_index = 0;
    pkt->flags |= PKT_FLAG_KEY;

    pkt->size= 0;
    for(i=0; i<3; i++){
        if(size[i]){
            ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]);
            if (!s->is_pipe)
                url_fclose(f[i]);
            if(ret[i]>0)
                pkt->size += ret[i];
        }
    }

    if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
        av_free_packet(pkt);
        return AVERROR_IO; /* signal EOF */
    } else {
        s->img_count++;
        s->img_number++;
        return 0;
    }
}
void close_video_file()
{
/* write the trailer, if any.  the trailer must be written
     * before you close the CodecContexts open when you wrote the
     * header; otherwise write_trailer may try to use memory that
     * was freed on av_codec_close() */
    av_write_trailer(oc);

    /* close each codec */
    if (video_st)
        close_video(oc, video_st);

    /* free the streams */
    for(i = 0; i < oc->nb_streams; i++) {
        av_freep(&oc->streams[i]->codec);
        av_freep(&oc->streams[i]);
    }

    if (!(fmt->flags & AVFMT_NOFILE)) {
        /* close the output file */
        url_fclose(oc->pb);
    }

    /* free the stream */
    av_free(oc);
}
static int list_open(URLContext *h, const char *filename, int flags)
{
	struct list_mgt *mgt;
	int ret;
	ByteIOContext *bio;
	mgt=av_malloc(sizeof(struct list_mgt));
	if(!mgt)
		return AVERROR(ENOMEM);
	memset(mgt,0,sizeof(*mgt));
	mgt->filename=filename+5;
	mgt->flags=flags;
	if((ret=list_open_internet(&bio,mgt,mgt->filename,flags| URL_MINI_BUFFER | URL_NO_LP_BUFFER))!=0)
	{
		av_free(mgt);
		return ret;
	}
	lp_lock_init(&mgt->mutex,NULL);
	mgt->current_item=mgt->item_list;
	mgt->cur_uio=NULL;
 	h->is_streamed=1;
	h->is_slowmedia=1;
	if(mgt->full_time>0 && mgt->have_list_end)
		h->support_time_seek=1;
	h->priv_data = mgt;
	
	url_fclose(bio);
	return 0;
}
Exemplo n.º 10
0
static int rtsp_read_close(AVFormatContext *s)
{
    RTSPState *rt = s->priv_data;
    RTSPHeader reply1, *reply = &reply1;
    char cmd[1024];

#if 0
    /* NOTE: it is valid to flush the buffer here */
    if (rt->protocol == RTSP_PROTOCOL_RTP_TCP) {
        url_fclose(&rt->rtsp_gb);
    }
#endif
    snprintf(cmd, sizeof(cmd),
             "TEARDOWN %s RTSP/1.0\r\n",
             s->filename);
    rtsp_send_cmd(s, cmd, reply, NULL);

    if (ff_rtsp_callback) {
        ff_rtsp_callback(RTSP_ACTION_CLIENT_TEARDOWN, rt->session_id,
                         NULL, 0, NULL);
    }

    rtsp_close_streams(rt);
    url_close(rt->rtsp_hd);
    return 0;
}
Exemplo n.º 11
0
static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
{
    VideoData *img = s->priv_data;
    ByteIOContext pb1, *pb;
    char filename[1024];

    if (!img->is_pipe) {
        if (get_frame_filename(filename, sizeof(filename), 
                               img->path, img->img_number) < 0 && img->img_number>1)
            return AVERROR_IO;
        pb = &pb1;
        if (url_fopen(pb, filename, URL_WRONLY) < 0)
            return AVERROR_IO;
    } else {
        pb = &s->pb;
    }

    put_buffer(pb, pkt->data, pkt->size);
    put_flush_packet(pb);
    if (!img->is_pipe) {
        url_fclose(pb);
    }

    img->img_number++;
    return 0;
}
Exemplo n.º 12
0
int main(int argc, char **argv)
{
	URL_FILE *handle;
	char buffer[BUFSIZE];

	if(argc > 1)
		strcpy(BASE,argv[1]);
	else {
		fprintf(stderr, "Usage: %s BaseURL\n",argv[0]);
		exit(1);
	}
		
	handle = url_fopen(BASE, "r");
	if (!handle) {
		fprintf(stderr,"couldn't url_fopen() %s\n", BASE);
		return 2;
	}
	while(!url_feof(handle)) {
		url_fgets(buffer,sizeof(buffer),handle);
		strlower(buffer);
		fputs(buffer,stdout);
		char *cur, link[BUFSIZE], full_link[BUFSIZE];
		cur = buffer;
		while ((cur = nextURL(cur)) != NULL) {
			getURL(cur, link, BUFSIZE-1);
			normalise(link, full_link, BUFSIZE-1);
			printf("%s\n",full_link);
			cur += strlen(link);
		}
	}

	url_fclose(handle);
	return 0;
}
Exemplo n.º 13
0
void VideoWriterThread::close()
{
    if (m_pOutputFormatContext) {
        av_write_trailer(m_pOutputFormatContext);
        avcodec_close(m_pVideoStream->codec);

        for (unsigned int i=0; i<m_pOutputFormatContext->nb_streams; i++) {
            AVStream* pStream = m_pOutputFormatContext->streams[i];

            pStream->discard = AVDISCARD_ALL;
            av_freep(&m_pOutputFormatContext->streams[i]->codec);
            av_freep(&m_pOutputFormatContext->streams[i]);
        }

        if (!(m_pOutputFormat->flags & AVFMT_NOFILE)) {
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53, 8, 0)
            avio_close(m_pOutputFormatContext->pb);
#else            
            url_fclose(m_pOutputFormatContext->pb);
#endif
        }

        av_free(m_pOutputFormatContext);
        av_free(m_pVideoBuffer);
        av_free(m_pConvertedFrame);
        av_free(m_pPictureBuffer);
        sws_freeContext(m_pFrameConversionContext);
        m_pOutputFormatContext = 0;
    }
}
Exemplo n.º 14
0
void CLOSE()
{
	mpg123_close(musicfile);
	mpg123_delete(musicfile);
	if ( fd > -1 )
	{
		close( fd );
		fd = -1;
	}

	if ( Type == 2 )
	{
		delete[] data;
		if ( f )
			url_fclose(f);
		f = NULL;
	}

	if ( Type == 2 )
		unloadCURL();

	IsPlaying = false;

	pix = QImage();
	id3Str.clear();

	_DATA_BUFF = 0;
}
Exemplo n.º 15
0
//___________________________________________________________________________
uint8_t lavMuxer::close( void )
{
	if(_running)
	{
		_running=0;
		// Flush
		// Cause deadlock :
		av_write_trailer(oc);
		url_fclose(&oc->pb);

	}
	if(audio_st)
	{
		 av_free(audio_st);
	}
	if(video_st)
	{
		 av_free(video_st);
	}
	video_st=NULL;
	audio_st=NULL;
	if(oc)
		av_free(oc);
	oc=NULL;
	return 1;
}
Exemplo n.º 16
0
/*=======================================================================================*/
int url_is_file_list(ByteIOContext *s,const char *filename)
{
	int ret;
	list_demux_t *demux;
	ByteIOContext *lio=s;
	int64_t	   *oldpos=0;
	if(!lio)
	{
		ret=url_fopen(&lio,filename,AVIO_FLAG_READ);
		if(ret!=0)
		{ 
		return AVERROR(EIO); 
		}
	}
	else{
		oldpos=url_ftell(lio);
	}
	demux=probe_demux(lio,filename);
	if(lio!=s)
	{
		url_fclose(lio);
	}
	else
	{
		url_fseek(lio, oldpos, SEEK_SET);
	}
	return demux!=NULL?100:0;
}
static int list_open_internet(ByteIOContext **pbio,struct list_mgt *mgt,const char *filename, int flags)
{
	list_demux_t *demux;
	int ret;
	ByteIOContext *bio;
	ret=url_fopen(&bio,filename,flags);
	if(ret!=0)
		{
			return AVERROR(EIO); 
		}
	demux=probe_demux(bio,filename);
	if(!demux)
	{
		ret=-1;
		goto error;
	}
	ret=demux->parser(mgt,bio);
	if(ret<=0)
	{
		ret=-1;
		goto error;
	}
	*pbio=bio;
	return 0;
error:
	if(bio)
		url_fclose(bio);
	return ret;
}
Exemplo n.º 18
0
/// Move on to next fragment IF NEEDED (changes file)
/// This method won't change file if it's not ready to
void advance_fragment(EncoderJob &jobSpec) {
	// Check to see if this frame should be split.
	if (should_advance(jobSpec)) {
		jobSpec.SplitNextKey = (jobSpec.a_pts > jobSpec.v_pts) ? (jobSpec.a_pts) : (jobSpec.v_pts);
		jobSpec.SegmentNumber++;

#ifdef NEW_M2TS
		jobSpec.p->CloseFile();
		sprintf(jobSpec.oc->filename, "%s-%05u.ts", jobSpec.BaseDirectory, jobSpec.SegmentNumber);
		int track_ids[2] = {120, 121};
		uint8_t track_types[2] = {Pests::TT_H264, Pests::TT_MpegAudio};
		jobSpec.p->StartFile(jobSpec.oc->filename, track_ids, track_types, 2);

#else
		url_fclose(jobSpec.oc->pb);
		sprintf(jobSpec.oc->filename, "%s-%05u.ts", jobSpec.BaseDirectory, jobSpec.SegmentNumber);
		if (url_fopen(&jobSpec.oc->pb, jobSpec.oc->filename, URL_WRONLY) < 0) {
			fprintf(stderr, "Could not open '%s'\n", jobSpec.oc->filename);
			jobSpec.IsValid = false;
			return;
		}
		av_write_header(jobSpec.oc);

#endif

	}
}
Exemplo n.º 19
0
AVFormatWriter::~AVFormatWriter()
{
    QMutexLocker locker(avcodeclock);

    if (m_pkt)
    {
        delete m_pkt;
        m_pkt = NULL;
    }

    if (m_ctx)
    {
        av_write_trailer(m_ctx);
        url_fclose(m_ctx->pb);
        for(unsigned int i = 0; i < m_ctx->nb_streams; i++) {
            av_freep(&m_ctx->streams[i]);
        }

        av_free(m_ctx);
        m_ctx = NULL;
    }

    if (m_videoOutBuf)
        delete [] m_videoOutBuf;
}
Exemplo n.º 20
0
VideoStream::~VideoStream()
{
	/* close each codec */
	if (ost)
	{
#if ZM_FFMPEG_SVN
		avcodec_close(ost->codec);
#else
		avcodec_close(&ost->codec);
#endif
		av_free(opicture->data[0]);
		av_free(opicture);
		if (tmp_opicture)
		{
			av_free(tmp_opicture->data[0]);
			av_free(tmp_opicture);
		}
		av_free(video_outbuf);
	}

	/* write the trailer, if any */
	av_write_trailer(ofc);
	
	/* free the streams */
	for( int i = 0; i < ofc->nb_streams; i++)
	{
		av_freep(&ofc->streams[i]);
	}

	if (!(of->flags & AVFMT_NOFILE))
	{
		/* close the output file */
#if ZM_FFMPEG_SVN
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1)
		avio_close(ofc->pb);
#else
		url_fclose(ofc->pb);
#endif
#else
		url_fclose(&ofc->pb);
#endif
	}

	/* free the stream */
	av_free(ofc);
}
Exemplo n.º 21
0
AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
                                       URLContext *handle, int packet_size)
{
    AVFormatContext *rtpctx;
    int ret;
    AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);

    if (!rtp_format)
        return NULL;

    /* Allocate an AVFormatContext for each output stream */
    rtpctx = avformat_alloc_context();
    if (!rtpctx)
        return NULL;

    rtpctx->oformat = rtp_format;
    if (!av_new_stream(rtpctx, 0)) {
        av_free(rtpctx);
        return NULL;
    }
    /* Copy the max delay setting; the rtp muxer reads this. */
    rtpctx->max_delay = s->max_delay;
    /* Copy other stream parameters. */
    rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;

    /* Set the synchronized start time. */
    rtpctx->start_time_realtime = s->start_time_realtime;

    /* Remove the local codec, link to the original codec
     * context instead, to give the rtp muxer access to
     * codec parameters. */
    av_free(rtpctx->streams[0]->codec);
    rtpctx->streams[0]->codec = st->codec;

    if (handle) {
        url_fdopen(&rtpctx->pb, handle);
    } else
        url_open_dyn_packet_buf(&rtpctx->pb, packet_size);
    ret = av_write_header(rtpctx);

    if (ret) {
        if (handle) {
            url_fclose(rtpctx->pb);
        } else {
            uint8_t *ptr;
            url_close_dyn_buf(rtpctx->pb, &ptr);
            av_free(ptr);
        }
        av_free(rtpctx->streams[0]);
        av_free(rtpctx);
        return NULL;
    }

    /* Copy the RTP AVStream timebase back to the original AVStream */
    st->time_base = rtpctx->streams[0]->time_base;
    return rtpctx;
}
Exemplo n.º 22
0
static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
{
    VideoData *img = s->priv_data;
    ByteIOContext pb1[3], *pb[3]= {&pb1[0], &pb1[1], &pb1[2]};
    char filename[1024];
    AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec;
    int i;

    if (!img->is_pipe) {
        if (av_get_frame_filename(filename, sizeof(filename),
                                  img->path, img->img_number) < 0 && img->img_number>1)
            return AVERROR_IO;
        for(i=0; i<3; i++){
            if (url_fopen(pb[i], filename, URL_WRONLY) < 0)
                return AVERROR_IO;

            if(codec->codec_id != CODEC_ID_RAWVIDEO)
                break;
            filename[ strlen(filename) - 1 ]= 'U' + i;
        }
    } else {
        pb[0] = &s->pb;
    }

    if(codec->codec_id == CODEC_ID_RAWVIDEO){
        int ysize = codec->width * codec->height;
        put_buffer(pb[0], pkt->data        , ysize);
        put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
        put_buffer(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2);
        put_flush_packet(pb[1]);
        put_flush_packet(pb[2]);
        url_fclose(pb[1]);
        url_fclose(pb[2]);
    }else{
        put_buffer(pb[0], pkt->data, pkt->size);
    }
    put_flush_packet(pb[0]);
    if (!img->is_pipe) {
        url_fclose(pb[0]);
    }

    img->img_number++;
    return 0;
}
Exemplo n.º 23
0
void VideoFFmpegWriter::finish()
{
	if( _error == IGNORE_FINISH )
		return;
	av_write_trailer( _avformatOptions );
	avcodec_close( _stream->codec );
	if( !( _avformatOptions->oformat->flags & AVFMT_NOFILE ) )
		url_fclose( _avformatOptions->pb );
	freeFormat();
}
Exemplo n.º 24
0
// note that there is no sane way to easily free a context w/o free_context()
// so this will probably leak
static void avformat_free_context(AVFormatContext *ctx)
{
    if(ctx->pb)
	url_fclose(ctx->pb);
    for(int i = 0; i < ctx->nb_streams; i++) {
	if(ctx->streams[i]->codec)
	    avcodec_close(ctx->streams[i]->codec);
	av_freep(&ctx->streams[i]->codec);
	av_freep(&ctx->streams[i]);
    }
    av_free(ctx);
}
Exemplo n.º 25
0
int sj_index_load(char *filename, SJ_IndexContext *sj_ic)
{
    ByteIOContext pb;
    register_protocol(&file_protocol);

    if (url_fopen(&pb, filename, URL_RDONLY) < 0) {
        // file could not be open
        return -1;
    }
    sj_ic->size = url_fsize(&pb) - HEADER_SIZE;
    sj_ic->index_num = (sj_ic->size / INDEX_SIZE);
    sj_ic->indexes = av_malloc(sj_ic->index_num * sizeof(Index));

    int64_t magic = get_le64(&pb);
    if (magic != 0x534A2D494E444558LL) {
        // not an index file
        url_fclose(&pb);
        return -2;
    }
    sj_ic->version = get_byte(&pb);
    sj_ic->start_pts = get_le64(&pb);
    sj_ic->start_dts = get_le64(&pb);
    sj_ic->start_timecode.frames = get_byte(&pb);
    sj_ic->start_timecode.seconds = get_byte(&pb);
    sj_ic->start_timecode.minutes = get_byte(&pb);
    sj_ic->start_timecode.hours = get_byte(&pb);

    if (!sj_ic->index_num) {
        // empty index
        url_fclose(&pb);
        return -4;
    }

    for(int i = 0; i < sj_ic->index_num; i++) {
        read_index(&sj_ic->indexes[i], &pb);
    }
    url_fclose(&pb);
    return 0;
}
/* XXX: use llseek */
static int64_t list_seek(URLContext *h, int64_t pos, int whence)
{
	struct list_mgt *mgt = h->priv_data;
	struct list_item *item,*item1;
	if (whence == AVSEEK_BUFFERED_TIME)
	{
		int64_t buffed_time=0;
		if(mgt->current_item && mgt->current_item->duration>0){
			//av_log(NULL, AV_LOG_INFO, "list_seek uui=%ld,size=%lld\n",mgt->cur_uio,url_fsize(mgt->cur_uio));
			if(mgt->cur_uio && url_fsize(mgt->cur_uio)>0)
{
				//av_log(NULL, AV_LOG_INFO, "list_seek start_time=%ld,pos=%lld\n",mgt->current_item->start_time,url_buffed_pos(mgt->cur_uio));
				buffed_time=mgt->current_item->start_time+url_buffed_pos(mgt->cur_uio)*mgt->current_item->duration/url_fsize(mgt->cur_uio);
			}
			else{
				buffed_time=mgt->current_item->start_time;
			}
		}
		av_log(NULL, AV_LOG_INFO, "list current buffed_time=%lld\n",buffed_time);
		return buffed_time;
	}
	
	av_log(NULL, AV_LOG_INFO, "list_seek pos=%lld,whence=%x\n",pos,whence);
	if (whence == AVSEEK_SIZE)
        return mgt->file_size;
	if (whence == AVSEEK_FULLTIME)
	{
		if(mgt->have_list_end)
			return mgt->full_time;
		else
			return -1;
	}
	
	if(whence == AVSEEK_TO_TIME && pos>=0 && pos<mgt->full_time)
	{
		av_log(NULL, AV_LOG_INFO, "list_seek to Time =%lld,whence=%x\n",pos,whence);
		for(item=mgt->item_list;item;item=item->next)
		{
			if(item->start_time<=pos && pos <item->start_time+item->duration)
			{	
				if(mgt->cur_uio)
					url_fclose(mgt->cur_uio);
				mgt->cur_uio=NULL;
				mgt->current_item=item;
				av_log(NULL, AV_LOG_INFO, "list_seek to item->file =%s\n",item->file);
				return item->start_time;/*pos=0;*/
			}
		}
	}
	av_log(NULL, AV_LOG_INFO, "list_seek failed\n");
	return -1;
Exemplo n.º 27
0
ComponentResult FFAvi_MovieImportValidateDataRef(ff_global_ptr storage, Handle dataRef, OSType dataRefType, UInt8 *valid)
{
	ComponentResult result = noErr;
	DataHandler dataHandler = NULL;
	uint8_t buf[PROBE_BUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE] = {0};
	AVProbeData pd;
	ByteIOContext *byteContext;

	/* default */
	*valid = 0;
	
	/* Get a data handle and read a probe of data */
	result = OpenADataHandler(dataRef, dataRefType, NULL, 0, NULL, kDataHCanRead, &dataHandler);
	if(result || !dataHandler) goto bail;
	
	pd.buf = buf;
	pd.buf_size = PROBE_BUF_SIZE;
	
	result = DataHScheduleData(dataHandler, (Ptr)pd.buf, 0, PROBE_BUF_SIZE, 0, NULL, NULL);
	require_noerr(result,bail);
	
	FFInitFFmpeg();
	storage->format = av_probe_input_format(&pd, 1);
	if(storage->format != NULL) {
		*valid = 255; /* This means we can read the data */
		
		/* we don't do MJPEG's Huffman tables right yet, and DV video seems to have 
		an aspect ratio coded in the bitstream that ffmpeg doesn't read, so let Apple's 
		AVI importer handle AVIs with these two video types */
		if (IS_AVI(storage->componentType)) {
			/* Prepare the iocontext structure */
			result = url_open_dataref(&byteContext, dataRef, dataRefType, NULL, NULL, NULL);
			require_noerr(result, bail);
			
			OSType fourcc = get_avi_strf_fourcc(byteContext);
			enum CodecID id = ff_codec_get_id(ff_codec_bmp_tags, BSWAP(fourcc));
			
			if (id == CODEC_ID_MJPEG || id == CODEC_ID_DVVIDEO || id == CODEC_ID_RAWVIDEO || id == CODEC_ID_MSVIDEO1 || id == CODEC_ID_MSRLE)
				*valid = 0;
			
			url_fclose(byteContext);
		}
	}
		
bail:
		if(dataHandler)
			CloseComponent(dataHandler);
	
	return result;
} /* FFAvi_MovieImportValidateDataRef() */
Exemplo n.º 28
0
/* Closes a video file. */
void ffmpeg_close(struct ffmpeg *ffmpeg)
{
    unsigned int i;

    /* close each codec */
    if (ffmpeg->video_st) {
        pthread_mutex_lock(&global_lock);
        avcodec_close(AVSTREAM_CODEC_PTR(ffmpeg->video_st));
        pthread_mutex_unlock(&global_lock);
        av_freep(&ffmpeg->picture);
        free(ffmpeg->video_outbuf);
    }

    /* write the trailer, if any */
    av_write_trailer(ffmpeg->oc);

    /* free the streams */
    for (i = 0; i < ffmpeg->oc->nb_streams; i++) 
        av_freep(&ffmpeg->oc->streams[i]);
    

    if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) {
        /* close the output file */
#if LIBAVFORMAT_BUILD >= (52<<16) 
        url_fclose(ffmpeg->oc->pb);
#else
        url_fclose(&ffmpeg->oc->pb);
#endif /* LIBAVFORMAT_BUILD >= (52<<16) */
    }

    /* free the stream */
    av_free(ffmpeg->oc);
#if LIBAVFORMAT_BUILD >= 4629
    av_free(ffmpeg->c);
#endif
    free(ffmpeg);
}
Exemplo n.º 29
0
QString InternetFormatSupport( const char* address )
{
	loadCURL();
	if ( !CURLloaded )
		return "";
	mpg123_handle *mus = mpg123_new(NULL, NULL);
	mpg123_open_feed( mus );
	URL_FILE *f = url_fopen( address );
	if ( !f )
	{
		unloadCURL();
		return "";
	}

	char *data;
	int _DATA_BUFF;
	if ( !getDataBuff( f, url_fread, _DATA_BUFF, &data ) )
	{
		url_fclose(f);
		unloadCURL();
		return "";
	}

	int bread = url_fread(data+10, 1, _DATA_BUFF-10, f);
	mpg123_decode( mus, (const unsigned char*)data, bread, 0,0,0 );
	bool loaded = getMusInfo( mus, 0,0,0,0,0, -1, "" );
	mpg123_close(mus);
	mpg123_delete(mus);
	delete[] data;
	url_fclose(f);
	unloadCURL();
	if ( loaded )
		return plugName;
	else
		return "";
}
Exemplo n.º 30
0
bool AVFormatWriter::CloseFile(void)
{
    if (m_ctx)
    {
        av_write_trailer(m_ctx);
        url_fclose(m_ctx->pb);
        for(unsigned int i = 0; i < m_ctx->nb_streams; i++) {
            av_freep(&m_ctx->streams[i]);
        }

        av_free(m_ctx);
        m_ctx = NULL;
    }

    return true;
}