/* src=NULL means lost packet */ static int decode(struct aucodec_st *st, struct mbuf *dst, struct mbuf *src) { uint16_t lengthv[MAX_FRAMES]; uint16_t total_length = 0; uint32_t i, n; int err = 0; DEBUG_INFO("decode %u bytes\n", mbuf_get_left(src)); if (st->low_overhead) { /* No length bytes */ for (i=0; i<st->bpfn && !err; i++) { err = decode_frame(st, dst, src, st->bpfv[i]); } } else { bool done = false; /* Read the length bytes */ for (i=0; i<ARRAY_SIZE(lengthv) && !done; i++) { uint8_t byte; if (mbuf_get_left(src) < 1) return EPROTO; /* Decode length */ lengthv[i] = 0; do { byte = mbuf_read_u8(src); lengthv[i] += byte; } while (byte == 0xff); total_length += lengthv[i]; if (total_length >= mbuf_get_left(src)) done = true; } n = i; DEBUG_INFO("decoded %d frames\n", n); for (i=0; i<n && !err; i++) { err = decode_frame(st, dst, src, lengthv[i]); } } return err; }
static ErrCode flic_next_frame(Flic *flic, BOOL fDecode) { FrameHead head; ErrCode err = 0; long size; if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) err = ErrFlicRead; else { if (head.type == FRAME_TYPE) { size = head.size - sizeof(head); /* Don't include head. */ if (size > 0) { if (size > 500000) { //TRACE("FLC chunk too big: %d\n",size); //Assert(0); FastDebugMsg(String("flic_next_frame: FLC chunk too big: %d", size)); size = 64000; } if (!(err = file_read_big_block(flic->file, pcxbuf, size))) { if ( fDecode ) err = decode_frame(flic, &head, (unsigned char *)pcxbuf); } } } else err = ErrFlicBadFrame; } return err; }
static GstVaapiDecoderStatus decode_ebdu(GstVaapiDecoderVC1 *decoder, GstVC1BDU *ebdu) { GstVaapiDecoderStatus status; GstVC1BDU rbdu; if (!decode_rbdu(decoder, &rbdu, ebdu)) return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; switch (ebdu->type) { case GST_VC1_SEQUENCE: status = decode_sequence(decoder, &rbdu, ebdu); break; case GST_VC1_ENTRYPOINT: status = decode_entry_point(decoder, &rbdu, ebdu); break; case GST_VC1_FRAME: status = decode_frame(decoder, &rbdu, ebdu); break; case GST_VC1_SLICE: GST_DEBUG("decode slice"); status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER; break; case GST_VC1_END_OF_SEQ: status = decode_sequence_end(decoder); break; default: GST_DEBUG("unsupported BDU type %d", ebdu->type); status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER; break; } return status; }
/* * Class: h264_com_VView * Method: DecoderNal * Signature: ([B[I)I */ jint Java_h264_com_VView_DecoderNal(JNIEnv* env, jobject thiz, jbyteArray in, jint nalLen, jbyteArray out) { int i; int imod; int got_picture; jbyte * Buf = (jbyte*)(*env)->GetByteArrayElements(env, in, 0); jbyte * Pixel= (jbyte*)(*env)->GetByteArrayElements(env, out, 0); int consumed_bytes = decode_frame(c, picture, &got_picture, Buf, nalLen); if(consumed_bytes > 0) { DisplayYUV_16((int*)Pixel, picture->data[0], picture->data[1], picture->data[2], c->width, c->height, picture->linesize[0], picture->linesize[1], iWidth); /* for(i=0; i<c->height; i++) fwrite(picture->data[0] + i * picture->linesize[0], 1, c->width, outf); for(i=0; i<c->height/2; i++) fwrite(picture->data[1] + i * picture->linesize[1], 1, c->width/2, outf); for(i=0; i<c->height/2; i++) fwrite(picture->data[2] + i * picture->linesize[2], 1, c->width/2, outf); // */ } (*env)->ReleaseByteArrayElements(env, in, Buf, 0); (*env)->ReleaseByteArrayElements(env, out, Pixel, 0); return consumed_bytes; }
/* decode almanac and ion/utc ------------------------------------------------*/ static int decode_alm1(int sat, raw_t *raw) { trace(4,"decode_alm1 : sat=%2d\n",sat); decode_frame(raw->subfrm[sat-1]+90,NULL,raw->nav.alm,raw->nav.ion_gps, raw->nav.utc_gps,&raw->nav.leaps); return 0; }
/* decode ephemeris ----------------------------------------------------------*/ static int decode_ephem(int sat, raw_t *raw) { eph_t eph={0}; trace(4,"decode_ephem: sat=%2d\n",sat); if (decode_frame(raw->subfrm[sat-1] ,&eph,NULL,NULL,NULL,NULL)!=1|| decode_frame(raw->subfrm[sat-1]+30,&eph,NULL,NULL,NULL,NULL)!=2|| decode_frame(raw->subfrm[sat-1]+60,&eph,NULL,NULL,NULL,NULL)!=3) return 0; if (eph.iode==raw->nav.eph[sat-1].iode) return 0; /* unchanged */ eph.sat=sat; raw->nav.eph[sat-1]=eph; raw->ephsat=sat; return 2; }
// Insert history into DB worker thread void insert_db_history(void *data) { int i; int num_elems = (int)data; // For an unknown reason, the cm160 sometimes sends a value > 12 for month // -> in that case we use the last valid month received. static int last_valid_month = 0; printf("insert %d elems\n", num_elems); printf("insert into db...\n"); clock_t cStartClock = clock(); db_begin_transaction(); for(i=0; i<num_elems; i++) { unsigned char *frame = history[i]; struct record_data rec; decode_frame(frame, &rec); if(rec.month < 0 || rec.month > 12) rec.month = last_valid_month; else last_valid_month = rec.month; db_insert_hist(&rec); printf("\r %.1f%%", min(100, 100*((double)i/num_elems))); fflush(stdout); } db_update_status(); db_end_transaction(); printf("\rinsert into db... 100%%\n"); fflush(stdout); printf("update db in %4.2f seconds\n", (clock() - cStartClock) / (double)CLOCKS_PER_SEC); }
GstVaapiDecoderStatus gst_vaapi_decoder_ffmpeg_decode(GstVaapiDecoder *decoder, GstBuffer *buffer) { GstVaapiDecoderFfmpeg * const ffdecoder = GST_VAAPI_DECODER_FFMPEG(decoder); GstVaapiDecoderFfmpegPrivate * const priv = ffdecoder->priv; GstClockTime inbuf_ts; guchar *outbuf; gint inbuf_ofs, inbuf_size, outbuf_size; gboolean got_frame; g_return_val_if_fail(priv->is_constructed, GST_VAAPI_DECODER_STATUS_ERROR_INIT_FAILED); if (!priv->is_opened) { priv->is_opened = gst_vaapi_decoder_ffmpeg_open(ffdecoder, buffer); if (!priv->is_opened) return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CODEC; } inbuf_ofs = 0; inbuf_size = GST_BUFFER_SIZE(buffer); inbuf_ts = GST_BUFFER_TIMESTAMP(buffer); if (priv->pctx) { do { int parsed_size = av_parser_parse2( priv->pctx, priv->avctx, &outbuf, &outbuf_size, GST_BUFFER_DATA(buffer) + inbuf_ofs, inbuf_size, inbuf_ts, inbuf_ts ,0 ); got_frame = outbuf && outbuf_size > 0; if (parsed_size > 0) { inbuf_ofs += parsed_size; inbuf_size -= parsed_size; } } while (!got_frame && inbuf_size > 0); inbuf_ts = priv->pctx->pts; } else { outbuf = GST_BUFFER_DATA(buffer); outbuf_size = inbuf_size; got_frame = outbuf && outbuf_size > 0; inbuf_ofs = inbuf_size; inbuf_size = 0; } if (inbuf_size > 0 && !gst_vaapi_decoder_push_buffer_sub(decoder, buffer, inbuf_ofs, inbuf_size)) return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; if (!got_frame && !GST_BUFFER_IS_EOS(buffer)) return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA; priv->in_timestamp = inbuf_ts; return decode_frame(ffdecoder, outbuf, outbuf_size); }
void stream_decoder::process(uchar* data, int len) { AVPacket * pkt =build_avpkt(data, len); if(pkt->size == 0) return; decode_frame(pkt); }
/* * Class: h264_com_VView * Method: DecoderNal * Signature: ([B[I)I */ jint Java_h264_com_VView_DecoderNal(JNIEnv* env, jobject thiz,jlong pDecoder,jbyteArray in, jint nalLen, jbyteArray out) { int i; int imod; int got_picture; if (pDecoder) { Decoder * de=(Decoder * )pDecoder; jbyte * Buf = (jbyte*)(*env)->GetByteArrayElements(env, in, 0); jbyte * Pixel= (jbyte*)(*env)->GetByteArrayElements(env, out, 0); int consumed_bytes = decode_frame(de->c, de->picture, &got_picture, Buf, nalLen); if(consumed_bytes > 0) { DisplayYUV_16((int*)Pixel, de->picture->data[0], de->picture->data[1], de->picture->data[2], de->c->width, de->c->height, de->picture->linesize[0], de->picture->linesize[1], de->c->width); } (*env)->ReleaseByteArrayElements(env, in, Buf, 0); (*env)->ReleaseByteArrayElements(env, out, Pixel, 0); return consumed_bytes; } else return 0; }
static status_t decode_frameset(decoders_ALACDecoder *self, unsigned *pcm_frames_read, int *samples) { BitstreamReader *br = self->bitstream; int channel_0[self->params.block_size]; int channel_1[self->params.block_size]; unsigned c = 0; unsigned block_size = self->params.block_size; unsigned channels = br->read(br, 3) + 1; while (channels != 8) { status_t status; unsigned frame_block_size; if ((channels != 1) && (channels != 2)) { /*only handle 1 or 2 channel frames*/ return INVALID_FRAME_CHANNEL_COUNT; } else if ((c + channels) > self->channels) { /*ensure one doesn't decode too many channels*/ return EXCESSIVE_FRAME_CHANNEL_COUNT; } if ((status = decode_frame(br, &(self->params), self->bits_per_sample, c == 0 ? &block_size : &frame_block_size, channels, channel_0, channel_1)) != OK) { return status; } else if ((c != 0) && (block_size != frame_block_size)) { return FRAME_BLOCK_SIZE_MISMATCH; } put_channel_data(samples, c++, self->channels, block_size, channel_0); if (channels == 2) { put_channel_data(samples, c++, self->channels, block_size, channel_1); } channels = br->read(br, 3) + 1; } br->byte_align(br); *pcm_frames_read = block_size; return OK; }
// backtrace Val backtrace() { Val anchor = list(0); Val last = anchor; foreach (Thread::EnumFrame, oEnum, MiniThread::Get()) { Frame* pFrame = oEnum.Get(); last = setf_cdr(list(decode_frame(pFrame)), last); } // for each frame
/* decode id#22 ephemeris data ------------------------------------------------*/ static int decode_ss2eph(raw_t *raw) { eph_t eph={0}; unsigned int tow; int i,j,prn,sat; unsigned char *p=raw->buff+4,buff[90]={0}; trace(4,"decode_ss2eph: len=%d\n",raw->len); if (raw->len!=79) { trace(2,"ss2 id#22 length error: len=%d\n",raw->len); return -1; } prn=(U4(p)&0x1F)+1; if (!(sat=satno(SYS_GPS,prn))) { trace(2,"ss2 id#22 satellite number error: prn=%d\n",prn); return -1; } if (raw->time.time==0) { trace(2,"ss2 id#22 week number unknown error\n"); return -1; } tow=(unsigned int)(time2gpst(raw->time,NULL)/6.0); for (i=0;i<3;i++) { buff[30*i+3]=(unsigned char)(tow>>9); /* add tow + subframe id */ buff[30*i+4]=(unsigned char)(tow>>1); buff[30*i+5]=(unsigned char)(((tow&1)<<7)+((i+1)<<2)); for (j=0;j<24;j++) buff[30*i+6+j]=p[1+24*i+j]; } if (decode_frame(buff ,&eph,NULL,NULL,NULL,NULL)!=1|| decode_frame(buff+30,&eph,NULL,NULL,NULL,NULL)!=2|| decode_frame(buff+60,&eph,NULL,NULL,NULL,NULL)!=3) { trace(2,"ss2 id#22 subframe error: prn=%d\n",prn); return -1; } if (eph.iode==raw->nav.eph[sat-1].iode) return 0; /* unchanged */ eph.sat=sat; eph.ttr=raw->time; raw->nav.eph[sat-1]=eph; raw->ephsat=sat; return 2; }
void file_decoder::run() { printf("Starting with file %s",path.c_str()); for (;;) { AVPacket * pkt = build_avpkt(&avpkt); if(pkt->size ==0) continue; decode_frame(pkt); } }
static void GetBuffer(demux_res_t *demux_res) { unsigned long destBufferSize = 1024*16; /* 16kb buffer = 4096 frames = 1 alac sample */ void *pDestBuffer = malloc(destBufferSize); int bytes_read = 0; unsigned int buffer_size = 1024*64; void *buffer; unsigned int i; buffer = malloc(buffer_size); for (i = 0; i < demux_res->num_sample_byte_sizes; i++) { uint32_t sample_duration; uint32_t sample_byte_size; int outputBytes; /* just get one sample for now */ if (!get_sample_info(demux_res, i, &sample_duration, &sample_byte_size)) { fprintf(stderr, "sample failed\n"); return; } if (buffer_size < sample_byte_size) { fprintf(stderr, "sorry buffer too small! (is %i want %i)\n", buffer_size, sample_byte_size); return; } stream_read(input_stream, sample_byte_size, buffer); /* now fetch */ outputBytes = destBufferSize; decode_frame(alac, buffer, pDestBuffer, &outputBytes); /* write */ bytes_read += outputBytes; if (verbose) fprintf(stderr, "read %i bytes. total: %i\n", outputBytes, bytes_read); fwrite(pDestBuffer, outputBytes, 1, output_file); } if (verbose) fprintf(stderr, "done reading, read %i frames\n", i); }
static OMX_ERRORTYPE h264d_prc_buffers_ready(const void *ap_obj) { vid_dec_PrivateType*priv = (vid_dec_PrivateType*) ap_obj; OMX_BUFFERHEADERTYPE *in_buf = NULL; OMX_BUFFERHEADERTYPE *out_buf = NULL; assert(priv); /* Set parameters if start of stream */ if (!priv->eos_ && priv->first_buf_in_frame && (in_buf = get_input_buffer(priv))) { decode_frame(priv, in_buf); } /* Don't get input buffer if output buffer not found */ while (!priv->eos_ && (out_buf = get_output_buffer(priv)) && (in_buf = get_input_buffer(priv))) { if (!priv->out_port_disabled_) { decode_frame(priv, in_buf); } } return OMX_ErrorNone; }
/* decode raw ephemereris ----------------------------------------------------*/ static int decode_gw10reph(raw_t *raw) { eph_t eph={0}; double tow; int i,week,prn,sat; unsigned char *p=raw->buff+2,buff[90]; trace(4,"decode_gw10reph: len=%d\n",raw->len); prn=U1(p); if (!(sat=satno(SYS_GPS,prn))) { trace(2,"gw10 raw ephemeris satellite number error: prn=%d\n",prn); return -1; } for (i=0;i<90;i++) { buff[i]=*(p+1+i); } if (decode_frame(buff ,&eph,NULL,NULL,NULL,NULL)!=1|| decode_frame(buff+ 30,&eph,NULL,NULL,NULL,NULL)!=2|| decode_frame(buff+ 60,&eph,NULL,NULL,NULL,NULL)!=3) { trace(2,"gw10 raw ephemeris navigation frame error: prn=%d\n",prn); return -1; } /* set time if no time avaliable */ if (raw->time.time==0) { tow=getbitu(buff,24,17)*6.0; week=getbitu(buff,48,10)+OFFWEEK; raw->time=timeadd(gpst2time(week,tow),24.0); } if (!strstr(raw->opt,"-EPHALL")) { if (eph.iode==raw->nav.eph[sat-1].iode) return 0; /* unchanged */ } eph.sat=sat; raw->nav.eph[sat-1]=eph; raw->ephsat=sat; return 2; }
void hst_decoders_framealigned_wrapper::process(void) { OMX_BUFFERHEADERTYPE * bufIn, * bufOut; if(mPorts[INPUT_PORT].queuedBufferCount() == 0 || mPorts[OUTPUT_PORT].queuedBufferCount() == 0) { return; } if(decoder.IsNullInterface() || !mCodecInitialized) { mCodecInitialized = false; mPorts[INPUT_PORT].dequeueAndReturnBuffer(); return; } bufIn = mPorts[INPUT_PORT].getBuffer(0); bufOut = mPorts[OUTPUT_PORT].getBuffer(0); // check that the buffer is a 32-bit multiple (since bs_init is 32bits) ARMNMF_DBC_ASSERT_MSG((bufOut->nAllocLen % BS_WORD_SIZE_IN_BYTES) == 0, "Buffer size not compliant with bs_init\n"); // the target registers on ARM are 32 bits... bs_init(&mBSRead, (unsigned int*)bufIn->pBuffer, (bufIn->nAllocLen/BS_WORD_SIZE_IN_BYTES), BS_INIT_SIZE_IN_BITS); mInterfaceFE.sample_struct.buf_add = (Float*)bufOut->pBuffer; decoder.setOutputBuf(&mInterfaceFE, bufOut->pBuffer); if ((bufIn->nFilledLen == 0) && (bufIn->nFlags & OMX_BUFFERFLAG_EOS)) { bufOut->nFilledLen = 0; bufOut->nFlags |= OMX_BUFFERFLAG_EOS; proxy.eventHandler(OMX_EventBufferFlag, OUTPUT_PORT, bufOut->nFlags); mPorts[OUTPUT_PORT].dequeueAndReturnBuffer(); mPorts[INPUT_PORT].dequeueAndReturnBuffer(); reset(); } else { if (mInterfaceFE.codec_state.remaining_blocks == 0) { check_synchro(bufIn); } decode_frame(bufIn, bufOut); } }
void alac_decode(short *dest, char *buf, int len) { unsigned char packet[MAX_PACKET]; assert(len<=MAX_PACKET); unsigned char iv[16]; int aeslen = len & ~0xf; memcpy(iv, aesiv, sizeof(iv)); AES_cbc_encrypt((unsigned char*)buf, packet, aeslen, &aes, iv, AES_DECRYPT); memcpy(packet+aeslen, buf+aeslen, len-aeslen); int outsize; decode_frame(decoder_info, packet, dest, &outsize); assert(outsize == FRAME_BYTES); }
int32_t ppb_video_decoder_decode(PP_Resource video_decoder, const struct PP_VideoBitstreamBuffer_Dev *bitstream_buffer, struct PP_CompletionCallback callback) { struct pp_video_decoder_s *vd = pp_resource_acquire(video_decoder, PP_RESOURCE_VIDEO_DECODER); if (!vd) { trace_error("%s, bad resource\n", __func__); return PP_ERROR_BADRESOURCE; } if (vd->failed_state) { trace_warning("%s, there were errors before, giving up\n", __func__); pp_resource_release(video_decoder); return PP_ERROR_FAILED; } void *rawdata = ppb_buffer_map(bitstream_buffer->data); if (!rawdata) { trace_error("%s, bad bitstream buffer\n", __func__); pp_resource_release(video_decoder); return PP_ERROR_FAILED; } uint8_t *inbuf = rawdata; size_t inbuf_sz = bitstream_buffer->size; while (inbuf_sz > 0) { uint8_t *outbuf = NULL; int outbuf_sz = 0; int len = av_parser_parse2(vd->avparser, vd->avctx, &outbuf, &outbuf_sz, inbuf, inbuf_sz, 0, 0, AV_NOPTS_VALUE); if (outbuf_sz > 0) decode_frame(vd, outbuf, outbuf_sz, vd->last_consumed_bitstream_buffer_id); inbuf += len; inbuf_sz -= len; } vd->last_consumed_bitstream_buffer_id = bitstream_buffer->id; ppb_buffer_unmap(bitstream_buffer->data); pp_resource_release(video_decoder); ppb_core_call_on_main_thread(0, callback, PP_OK); return PP_OK_COMPLETIONPENDING; }
void alac_decode(short *dest, char *buf, int len) { unsigned char packet[MAX_PACKET]; assert(len<=MAX_PACKET); unsigned char iv[16]; int i; memcpy(iv, aesiv, sizeof(iv)); for (i=0; i+16<=len; i += 16) AES_cbc_encrypt((unsigned char*)buf+i, packet+i, 0x10, &aes, iv, AES_DECRYPT); if (len & 0xf) memcpy(packet+i, buf+i, len & 0xf); int outsize; decode_frame(decoder_info, packet, dest, &outsize); assert(outsize == FRAME_BYTES); }
int ffmpegWrap::next_frame() { int rc = RC_FAILURE; if (pkg_.size == 0) { rc = av_read_frame(ic_, &pkg_); if (rc < 0) { return RC_FAILURE; } } rc = decode_frame(ic_->streams[pkg_.stream_index], &pkg_); if (pkg_.size == 0) { av_free_packet(&pkg_); } return rc; }
int Mp3Decoder::decode_audio(sh_audio_t *sh_audio,unsigned char **inbuf,int *inlen,unsigned char* outbuf,int *outlen) { mad_decoder_t *mad_dec = (mad_decoder_t *) sh_audio->context; int consume; *outlen=0; if(sh_audio->ds && sh_audio->ds->seek_flag > 0){ mad_stream_init (&mad_dec->stream); a_in_buffer_len = 0; sh_audio->ds->seek_flag = 0; } //if(*inlen == 0) // return 0; memcpy(buffer + a_in_buffer_len,*inbuf,*inlen); a_in_buffer_len += *inlen; *inbuf += *inlen; *inlen = 0; EL("a_in_buffer_len: %d",a_in_buffer_len); consume = decode_frame(sh_audio,outbuf,outlen); return *outlen; }
static int flac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; FLACContext *s = avctx->priv_data; int bytes_read = 0; int ret; *got_frame_ptr = 0; if (s->max_framesize == 0) { s->max_framesize = ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE, FLAC_MAX_CHANNELS, 32); } /* check that there is at least the smallest decodable amount of data. this amount corresponds to the smallest valid FLAC frame possible. FF F8 69 02 00 00 9A 00 00 34 46 */ if (buf_size < FLAC_MIN_FRAME_SIZE) return buf_size; /* check for inline header */ if (AV_RB32(buf) == MKBETAG('f','L','a','C')) { if (!s->got_streaminfo && (ret = parse_streaminfo(s, buf, buf_size))) { av_log(s->avctx, AV_LOG_ERROR, "invalid header\n"); return ret; } return get_metadata_size(buf, buf_size); } /* decode frame */ init_get_bits(&s->gb, buf, buf_size*8); if ((ret = decode_frame(s)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); return ret; } bytes_read = (get_bits_count(&s->gb)+7)/8; /* get output buffer */ frame->nb_samples = s->blocksize; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } s->dsp.decorrelate[s->ch_mode](frame->data, s->decoded, s->channels, s->blocksize, s->sample_shift); if (bytes_read > buf_size) { av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", bytes_read - buf_size); return AVERROR_INVALIDDATA; } if (bytes_read < buf_size) { av_log(s->avctx, AV_LOG_DEBUG, "underread: %d orig size: %d\n", buf_size - bytes_read, buf_size); } *got_frame_ptr = 1; return bytes_read; }
static int flac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; FLACContext *s = avctx->priv_data; int bytes_read = 0; int ret; *got_frame_ptr = 0; if (s->max_framesize == 0) { s->max_framesize = ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE, FLAC_MAX_CHANNELS, 32); } if (buf_size > 5 && !memcmp(buf, "\177FLAC", 5)) { av_log(s->avctx, AV_LOG_DEBUG, "skiping flac header packet 1\n"); return buf_size; } if (buf_size > 0 && (*buf & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) { av_log(s->avctx, AV_LOG_DEBUG, "skiping vorbis comment\n"); return buf_size; } /* check that there is at least the smallest decodable amount of data. this amount corresponds to the smallest valid FLAC frame possible. FF F8 69 02 00 00 9A 00 00 34 46 */ if (buf_size < FLAC_MIN_FRAME_SIZE) return buf_size; /* check for inline header */ if (AV_RB32(buf) == MKBETAG('f','L','a','C')) { if (!s->got_streaminfo && parse_streaminfo(s, buf, buf_size)) { av_log(s->avctx, AV_LOG_ERROR, "invalid header\n"); return -1; } return get_metadata_size(buf, buf_size); } /* decode frame */ init_get_bits(&s->gb, buf, buf_size*8); if (decode_frame(s) < 0) { av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); return -1; } bytes_read = (get_bits_count(&s->gb)+7)/8; /* get output buffer */ s->frame.nb_samples = s->blocksize; if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } s->dsp.decorrelate[s->ch_mode](s->frame.data, s->decoded, s->channels, s->blocksize, s->sample_shift); if (bytes_read > buf_size) { av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", bytes_read - buf_size); return -1; } if (bytes_read < buf_size) { av_log(s->avctx, AV_LOG_DEBUG, "underread: %d orig size: %d\n", buf_size - bytes_read, buf_size); } *got_frame_ptr = 1; *(AVFrame *)data = s->frame; return bytes_read; }
int get_scaled_frame_at_time(State **ps, int64_t timeUs, int option, AVPacket *pkt, int width, int height) { printf("get_frame_at_time\n"); int got_packet = 0; int64_t desired_frame_number = -1; State *state = *ps; Options opt = option; if (!state || !state->pFormatCtx || state->video_stream < 0) { return FAILURE; } if (timeUs != -1) { int stream_index = state->video_stream; int64_t seek_time = av_rescale_q(timeUs, AV_TIME_BASE_Q, state->pFormatCtx->streams[stream_index]->time_base); int64_t seek_stream_duration = state->pFormatCtx->streams[stream_index]->duration; int flags = 0; int ret = -1; // For some reason the seek_stream_duration is sometimes a negative value, // make sure to check that it is greater than 0 before adjusting the // seek_time if (seek_stream_duration > 0 && seek_time > seek_stream_duration) { seek_time = seek_stream_duration; } if (seek_time < 0) { return FAILURE; } if (opt == OPTION_CLOSEST) { desired_frame_number = seek_time; flags = AVSEEK_FLAG_BACKWARD; } else if (opt == OPTION_CLOSEST_SYNC) { flags = 0; } else if (opt == OPTION_NEXT_SYNC) { flags = 0; } else if (opt == OPTION_PREVIOUS_SYNC) { flags = AVSEEK_FLAG_BACKWARD; } ret = av_seek_frame(state->pFormatCtx, stream_index, seek_time, flags); if (ret < 0) { return FAILURE; } else { if (state->audio_stream >= 0) { avcodec_flush_buffers(state->audio_st->codec); } if (state->video_stream >= 0) { avcodec_flush_buffers(state->video_st->codec); } } } decode_frame(state, pkt, &got_packet, desired_frame_number, width, height); if (got_packet) { return SUCCESS; } else { return FAILURE; } }
int main(int argc, char** argv) { FILE *infile,*outfile; decoder_info_t decoder_info; stream_t stream; yuv_frame_t rec[MAX_REORDER_BUFFER]; yuv_frame_t ref[MAX_REF_FRAMES]; int rec_available[MAX_REORDER_BUFFER]={0}; int rec_buffer_idx; int op_rec_buffer_idx; int decode_frame_num = 0; int last_frame_output = -1; int done = 0; int width; int height; int r; init_use_simd(); parse_arg(argc, argv, &infile, &outfile); fseek(infile, 0, SEEK_END); int input_file_size = ftell(infile); fseek(infile, 0, SEEK_SET); initbits_dec(infile, &stream); decoder_info.stream = &stream; memset(&decoder_info.bit_count,0,sizeof(bit_count_t)); int bit_start = stream.bitcnt; /* Read sequence header */ width = getbits(&stream,16); height = getbits(&stream,16); decoder_info.width = width; decoder_info.height = height; printf("width=%4d height=%4d\n",width,height); decoder_info.pb_split = getbits(&stream,1); printf("pb_split_enable=%1d\n",decoder_info.pb_split); //TODO: Rename variable to pb_split_enable decoder_info.tb_split_enable = getbits(&stream,1); printf("tb_split_enable=%1d\n",decoder_info.tb_split_enable); decoder_info.max_num_ref = getbits(&stream,2) + 1; fprintf(stderr,"num refs is %d\n",decoder_info.max_num_ref); decoder_info.interp_ref = getbits(&stream,1); decoder_info.max_delta_qp = getbits(&stream, 1); decoder_info.deblocking = getbits(&stream,1); decoder_info.clpf = getbits(&stream,1); decoder_info.use_block_contexts = getbits(&stream,1); decoder_info.bipred = getbits(&stream,1); decoder_info.bit_count.sequence_header += (stream.bitcnt - bit_start); for (r=0;r<MAX_REORDER_BUFFER;r++){ create_yuv_frame(&rec[r],width,height,0,0,0,0); } for (r=0;r<MAX_REF_FRAMES;r++){ create_yuv_frame(&ref[r],width,height,PADDING_Y,PADDING_Y,PADDING_Y/2,PADDING_Y/2); decoder_info.ref[r] = &ref[r]; } if (decoder_info.interp_ref) { for (r=0;r<MAX_SKIP_FRAMES;r++){ decoder_info.interp_frames[r] = malloc(sizeof(yuv_frame_t)); create_yuv_frame(decoder_info.interp_frames[r],width,height,PADDING_Y,PADDING_Y,PADDING_Y/2,PADDING_Y/2); } } decoder_info.deblock_data = (deblock_data_t *)malloc((height/MIN_PB_SIZE) * (width/MIN_PB_SIZE) * sizeof(deblock_data_t)); do { decoder_info.frame_info.decode_order_frame_num = decode_frame_num; decode_frame(&decoder_info,rec); rec_buffer_idx = decoder_info.frame_info.display_frame_num%MAX_REORDER_BUFFER; rec_available[rec_buffer_idx]=1; done = initbits_dec(infile, &stream); op_rec_buffer_idx = (last_frame_output+1)%MAX_REORDER_BUFFER; if (rec_available[op_rec_buffer_idx]) { last_frame_output++; write_yuv_frame(&rec[op_rec_buffer_idx],width,height,outfile); rec_available[op_rec_buffer_idx] = 0; } printf("decode_frame_num=%4d display_frame_num=%4d input_file_size=%12d bitcnt=%12d\n", decode_frame_num,decoder_info.frame_info.display_frame_num,input_file_size,stream.bitcnt); decode_frame_num++; } while (!done); // Output the tail int i,j; for (i=1; i<=MAX_REORDER_BUFFER; ++i) { op_rec_buffer_idx=(last_frame_output+i) % MAX_REORDER_BUFFER; if (rec_available[op_rec_buffer_idx]) write_yuv_frame(&rec[op_rec_buffer_idx],width,height,outfile); else break; } bit_count_t bit_count = decoder_info.bit_count; uint32_t tot_bits[NUM_FRAME_TYPES] = {0}; for (i=0;i<NUM_FRAME_TYPES;i++){ tot_bits[i] = bit_count.frame_header[i] + bit_count.super_mode[i] + bit_count.intra_mode[i] + bit_count.mv[i] + bit_count.skip_idx[i] + bit_count.coeff_y[i] + bit_count.coeff_u[i] + bit_count.coeff_v[i] + bit_count.cbp[i] + bit_count.clpf[i]; } tot_bits[0] += bit_count.sequence_header; int ni = bit_count.frame_type[0]; int np = bit_count.frame_type[1]; int nb = bit_count.frame_type[2]; if (np==0) np = (1<<30); //Hack to avoid division by zero if there are no P frames if (nb==0) nb = (1<<30); //Hack to avoid division by zero if there are no B frames printf("\n\nBIT STATISTICS:\n"); printf("Sequence header: %4d\n",bit_count.sequence_header); printf(" I pictures: P pictures: B pictures:\n"); printf(" total average total average total average\n"); printf("Frame header: %9d %9d %9d %9d %9d %9d\n",bit_count.frame_header[0],bit_count.frame_header[0]/ni,bit_count.frame_header[1],bit_count.frame_header[1]/np,bit_count.frame_header[2],bit_count.frame_header[2]/nb); printf("Super mode: %9d %9d %9d %9d %9d %9d\n",bit_count.super_mode[0],bit_count.super_mode[0]/ni,bit_count.super_mode[1],bit_count.super_mode[1]/np,bit_count.super_mode[2],bit_count.super_mode[2]/nb); printf("Intra mode: %9d %9d %9d %9d %9d %9d\n",bit_count.intra_mode[0],bit_count.intra_mode[0]/ni,bit_count.intra_mode[1],bit_count.intra_mode[1]/np, bit_count.intra_mode[2],bit_count.intra_mode[2]/nb); printf("MV: %9d %9d %9d %9d %9d %9d\n",bit_count.mv[0],bit_count.mv[0],bit_count.mv[1],bit_count.mv[1]/np, bit_count.mv[2],bit_count.mv[2]/nb); printf("Skip idx: %9d %9d %9d %9d %9d %9d\n",bit_count.skip_idx[0],bit_count.skip_idx[0],bit_count.skip_idx[1],bit_count.skip_idx[1]/np,bit_count.skip_idx[2],bit_count.skip_idx[2]/nb); printf("Coeff_y: %9d %9d %9d %9d %9d %9d\n",bit_count.coeff_y[0],bit_count.coeff_y[0]/ni,bit_count.coeff_y[1],bit_count.coeff_y[1]/np,bit_count.coeff_y[2],bit_count.coeff_y[2]/nb); printf("Coeff_u: %9d %9d %9d %9d %9d %9d\n",bit_count.coeff_u[0],bit_count.coeff_u[0]/ni,bit_count.coeff_u[1],bit_count.coeff_u[1]/np,bit_count.coeff_u[2],bit_count.coeff_u[2]/nb); printf("Coeff_v: %9d %9d %9d %9d %9d %9d\n",bit_count.coeff_v[0],bit_count.coeff_v[0]/ni,bit_count.coeff_v[1],bit_count.coeff_v[1]/np,bit_count.coeff_v[2],bit_count.coeff_v[2]/nb); printf("CBP (TU-split): %9d %9d %9d %9d %9d %9d\n",bit_count.cbp[0],bit_count.cbp[0]/ni,bit_count.cbp[1],bit_count.cbp[1]/np,bit_count.cbp[2],bit_count.cbp[2]/nb); printf("CLPF: %9d %9d %9d %9d %9d %9d\n",bit_count.clpf[0],bit_count.clpf[0]/ni,bit_count.clpf[1],bit_count.clpf[1]/np,bit_count.clpf[2],bit_count.clpf[2]/nb); printf("Total: %9d %9d %9d %9d %9d %9d\n",tot_bits[0],tot_bits[0],tot_bits[1],tot_bits[1]/np,tot_bits[2],tot_bits[2]/nb); printf("---------------------------------------------------------------------------------------\n\n"); printf("PARAMETER STATISTICS:\n"); printf(" I pictures: P pictures: B pictures:\n"); printf(" total average total average total average\n"); printf("Skip-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.mode[0][0],bit_count.mode[0][0]/ni,bit_count.mode[1][0],bit_count.mode[1][0]/np,bit_count.mode[2][0],bit_count.mode[2][0]/nb); printf("Intra-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.mode[0][1],bit_count.mode[0][1]/ni,bit_count.mode[1][1],bit_count.mode[1][1]/np,bit_count.mode[2][1],bit_count.mode[2][1]/nb); printf("Inter-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.mode[0][2],bit_count.mode[0][2]/ni,bit_count.mode[1][2],bit_count.mode[1][2]/np,bit_count.mode[2][2],bit_count.mode[2][2]/nb); printf("Bipred-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.mode[0][3],bit_count.mode[0][3]/ni,bit_count.mode[1][3],bit_count.mode[1][3]/np,bit_count.mode[2][3],bit_count.mode[2][3]/nb); printf("Merge-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.mode[0][4],bit_count.mode[0][4]/ni,bit_count.mode[1][4],bit_count.mode[1][4]/np,bit_count.mode[2][4],bit_count.mode[2][4]/nb); printf("\n"); printf("8x8-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.size[0][0],bit_count.size[0][0]/ni,bit_count.size[1][0],bit_count.size[1][0]/np,bit_count.size[2][0],bit_count.size[2][0]/nb); printf("16x16-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.size[0][1],bit_count.size[0][1]/ni,bit_count.size[1][1],bit_count.size[1][1]/np,bit_count.size[2][1],bit_count.size[2][1]/nb); printf("32x32-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.size[0][2],bit_count.size[0][2]/ni,bit_count.size[1][2],bit_count.size[1][2]/np,bit_count.size[2][2],bit_count.size[2][2]/nb); printf("64x64-blocks (8x8): %9d %9d %9d %9d %9d %9d\n",bit_count.size[0][3],bit_count.size[0][3]/ni,bit_count.size[1][3],bit_count.size[1][3]/np,bit_count.size[2][3],bit_count.size[2][3]/nb); printf("\n"); printf("Mode and size distribution for P pictures:\n"); printf(" SKIP INTRA INTER BIPRED MERGE\n"); printf("8x8-blocks (8x8): %9d %9d %9d %9d %9d\n",bit_count.size_and_mode[P_FRAME][0][0],bit_count.size_and_mode[P_FRAME][0][1],bit_count.size_and_mode[P_FRAME][0][2],bit_count.size_and_mode[P_FRAME][0][3],bit_count.size_and_mode[P_FRAME][0][4]); printf("16x16-blocks (8x8): %9d %9d %9d %9d %9d\n",bit_count.size_and_mode[P_FRAME][1][0],bit_count.size_and_mode[P_FRAME][1][1],bit_count.size_and_mode[P_FRAME][1][2],bit_count.size_and_mode[P_FRAME][1][3],bit_count.size_and_mode[P_FRAME][1][4]); printf("32x32-blocks (8x8): %9d %9d %9d %9d %9d\n",bit_count.size_and_mode[P_FRAME][2][0],bit_count.size_and_mode[P_FRAME][2][1],bit_count.size_and_mode[P_FRAME][2][2],bit_count.size_and_mode[P_FRAME][2][3],bit_count.size_and_mode[P_FRAME][2][4]); printf("64x64-blocks (8x8): %9d %9d %9d %9d %9d\n",bit_count.size_and_mode[P_FRAME][3][0],bit_count.size_and_mode[P_FRAME][3][1],bit_count.size_and_mode[P_FRAME][3][2],bit_count.size_and_mode[P_FRAME][3][3],bit_count.size_and_mode[P_FRAME][3][4]); printf("\n"); printf("Mode and size distribution for B pictures:\n"); printf(" SKIP INTRA INTER BIPRED MERGE\n"); printf("8x8-blocks (8x8): %9d %9d %9d %9d %9d\n", bit_count.size_and_mode[B_FRAME][0][0], bit_count.size_and_mode[B_FRAME][0][1], bit_count.size_and_mode[B_FRAME][0][2], bit_count.size_and_mode[B_FRAME][0][3], bit_count.size_and_mode[B_FRAME][0][4]); printf("16x16-blocks (8x8): %9d %9d %9d %9d %9d\n", bit_count.size_and_mode[B_FRAME][1][0], bit_count.size_and_mode[B_FRAME][1][1], bit_count.size_and_mode[B_FRAME][1][2], bit_count.size_and_mode[B_FRAME][1][3], bit_count.size_and_mode[B_FRAME][1][4]); printf("32x32-blocks (8x8): %9d %9d %9d %9d %9d\n", bit_count.size_and_mode[B_FRAME][2][0], bit_count.size_and_mode[B_FRAME][2][1], bit_count.size_and_mode[B_FRAME][2][2], bit_count.size_and_mode[B_FRAME][2][3], bit_count.size_and_mode[B_FRAME][2][4]); printf("64x64-blocks (8x8): %9d %9d %9d %9d %9d\n", bit_count.size_and_mode[B_FRAME][3][0], bit_count.size_and_mode[B_FRAME][3][1], bit_count.size_and_mode[B_FRAME][3][2], bit_count.size_and_mode[B_FRAME][3][3], bit_count.size_and_mode[B_FRAME][3][4]); int idx; int num = 5 + decoder_info.max_num_ref; printf("\nSuper-mode distribution for P pictures:\n"); printf(" SKIP SPLIT INTERr0 MERGE BIPRED INTRA "); for (i = 1; i < decoder_info.max_num_ref; i++) printf("INTERr%1d ", i); printf("\n"); for (idx=0;idx<NUM_BLOCK_SIZES;idx++){ int size = 8<<idx; printf("%2d x %2d-blocks: ",size,size); for (i=0;i<num;i++){ printf("%8d",bit_count.super_mode_stat[P_FRAME][idx][i]); } printf("\n"); } printf("\nSuper-mode distribution for B pictures:\n"); printf(" SKIP SPLIT INTERr0 MERGE BIPRED INTRA "); for (i = 1; i < decoder_info.max_num_ref; i++) printf("INTERr%1d ", i); printf("\n"); for (idx = 0; idx<NUM_BLOCK_SIZES; idx++) { int size = 8 << idx; printf("%2d x %2d-blocks: ", size, size); for (i = 0; i<num; i++) { printf("%8d", bit_count.super_mode_stat[B_FRAME][idx][i]); } printf("\n"); } int size; int max_num_ref = 4; printf("\n"); printf("Ref_idx and size distribution for P pictures:\n"); for (i=0;i<NUM_BLOCK_SIZES;i++){ size = 1<<(i+3); printf("%2d x %2d-blocks: ",size,size); for (j=0;j<decoder_info.max_num_ref;j++){ printf("%6d",bit_count.size_and_ref_idx[P_FRAME][i][j]); } printf("\n"); } printf("\n"); printf("Ref_idx and size distribution for B pictures:\n"); for (i = 0; i<NUM_BLOCK_SIZES; i++) { size = 1 << (i + 3); printf("%2d x %2d-blocks: ", size, size); for (j = 0; j<decoder_info.max_num_ref; j++) { printf("%6d", bit_count.size_and_ref_idx[B_FRAME][i][j]); } printf("\n"); } printf("\n"); printf("bi-ref-P: "); for (j=0;j<max_num_ref*max_num_ref;j++){ printf("%7d",bit_count.bi_ref[P_FRAME][j]); } printf("\n"); printf("bi-ref-B: "); for (j = 0; j<max_num_ref*max_num_ref; j++) { printf("%7d", bit_count.bi_ref[B_FRAME][j]); } printf("\n"); printf("-----------------------------------------------------------------\n"); for (r=0;r<MAX_REORDER_BUFFER;r++){ close_yuv_frame(&rec[r]); } for (r=0;r<MAX_REF_FRAMES;r++){ close_yuv_frame(&ref[r]); } if (decoder_info.interp_ref) { for (r=0;r<MAX_SKIP_FRAMES;r++){ close_yuv_frame(decoder_info.interp_frames[r]); free(decoder_info.interp_frames[r]); } } free(decoder_info.deblock_data); return 0; }
static int flac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { AVFrame *frame = data; ThreadFrame tframe = { .f = data }; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; FLACContext *s = avctx->priv_data; int bytes_read = 0; int ret; *got_frame_ptr = 0; if (s->max_framesize == 0) { s->max_framesize = ff_flac_get_max_frame_size(s->max_blocksize ? s->max_blocksize : FLAC_MAX_BLOCKSIZE, FLAC_MAX_CHANNELS, 32); } if (buf_size > 5 && !memcmp(buf, "\177FLAC", 5)) { av_log(s->avctx, AV_LOG_DEBUG, "skipping flac header packet 1\n"); return buf_size; } if (buf_size > 0 && (*buf & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) { av_log(s->avctx, AV_LOG_DEBUG, "skipping vorbis comment\n"); return buf_size; } /* check that there is at least the smallest decodable amount of data. this amount corresponds to the smallest valid FLAC frame possible. FF F8 69 02 00 00 9A 00 00 34 46 */ if (buf_size < FLAC_MIN_FRAME_SIZE) return buf_size; /* check for inline header */ if (AV_RB32(buf) == MKBETAG('f','L','a','C')) { if (!s->got_streaminfo && (ret = parse_streaminfo(s, buf, buf_size))) { av_log(s->avctx, AV_LOG_ERROR, "invalid header\n"); return ret; } return get_metadata_size(buf, buf_size); } /* decode frame */ if ((ret = init_get_bits8(&s->gb, buf, buf_size)) < 0) return ret; if ((ret = decode_frame(s)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); return ret; } bytes_read = get_bits_count(&s->gb)/8; if ((s->avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_COMPLIANT)) && av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf, bytes_read)) { av_log(s->avctx, AV_LOG_ERROR, "CRC error at PTS %"PRId64"\n", avpkt->pts); if (s->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } /* get output buffer */ frame->nb_samples = s->blocksize; if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0) return ret; s->dsp.decorrelate[s->ch_mode](frame->data, s->decoded, s->channels, s->blocksize, s->sample_shift); if (bytes_read > buf_size) { av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", bytes_read - buf_size); return AVERROR_INVALIDDATA; } if (bytes_read < buf_size) { av_log(s->avctx, AV_LOG_DEBUG, "underread: %d orig size: %d\n", buf_size - bytes_read, buf_size); } *got_frame_ptr = 1; return bytes_read; }
void MediaThread::run() { const char *url = url_.c_str(); ic_ = 0; int rc = avformat_open_input(&ic_, url, 0, 0); if (rc < 0) { fprintf(stderr, "ERR: avformat_open_input can't open %s\n", url); return; } rc = avformat_find_stream_info(ic_, 0); if (rc < 0) { fprintf(stderr, "ERR: avformat_find_stream_info fault!\n"); avformat_close_input(&ic_); return; } av_dump_format(ic_, -1, url, 0); for (int i = 0; i < ic_->nb_streams; i++) { AVCodecContext *ctx = ic_->streams[i]->codec; AVCodec *codec = avcodec_find_decoder(ctx->codec_id); if (!codec) { fprintf(stderr, "ERR: avcodec_find_decoder NOT find %d\n", ctx->codec_id); avformat_close_input(&ic_); return; } avcodec_open2(ctx, codec, 0); } bool err = false; AVFrame *frame = av_frame_alloc(); while (1) { int code; if (chk_req(0, &code)) { if (code == 0) { reply(0); break; } } if (err) { code = get_req(); if (code == 0) { reply(0); break; } } else { AVPacket pkg; rc = av_read_frame(ic_, &pkg); if (rc < 0) { err = true; continue; } int got; do { got = decode_frame(frame, &pkg); if (got) { dr_->save_video_frame(frame); } } while (got); av_free_packet(&pkg); } } avformat_close_input(&ic_); av_frame_free(&frame); }
/* decode gps message --------------------------------------------------------*/ static int decode_gw10gps(raw_t *raw) { eph_t eph={0}; double tow,ion[8]={0},utc[4]={0}; unsigned int buff=0; int i,prn,sat,id,leaps; unsigned char *p=raw->buff+2,subfrm[30]; trace(4,"decode_gw10gps: len=%d\n",raw->len); tow=U4(p)/1000.0; p+=4; prn=U1(p); p+=1; if (!(sat=satno(SYS_GPS,prn))) { trace(2,"gw10 gps satellite number error: tow=%.1f prn=%d\n",tow,prn); return -1; } for (i=0;i<10;i++) { buff=(buff<<30)|U4(p); p+=4; /* check parity of word */ if (!check_parity(buff,subfrm+i*3)) { trace(2,"gw10 gps frame parity error: tow=%.1f prn=%2d word=%2d\n", tow,prn,i+1); return -1; } } id=getbitu(subfrm,43,3); /* subframe id */ if (id<1||5<id) { trace(2,"gw10 gps frame id error: tow=%.1f prn=%2d id=%d\n",tow,prn,id); return -1; } for (i=0;i<30;i++) raw->subfrm[sat-1][i+(id-1)*30]=subfrm[i]; if (id==3) { /* decode ephemeris */ if (decode_frame(raw->subfrm[sat-1] ,&eph,NULL,NULL,NULL,NULL)!=1|| decode_frame(raw->subfrm[sat-1]+30,&eph,NULL,NULL,NULL,NULL)!=2|| decode_frame(raw->subfrm[sat-1]+60,&eph,NULL,NULL,NULL,NULL)!=3) { return 0; } if (!strstr(raw->opt,"-EPHALL")) { if (eph.iode==raw->nav.eph[sat-1].iode) return 0; /* unchanged */ } eph.sat=sat; raw->nav.eph[sat-1]=eph; raw->ephsat=sat; return 2; } else if (id==4) { /* decode ion-utc parameters */ if (decode_frame(subfrm,NULL,NULL,ion,utc,&leaps)!=4) { return 0; } if (norm(ion,8)>0.0&&norm(utc,4)>0.0&&leaps!=0) { for (i=0;i<8;i++) raw->nav.ion_gps[i]=ion[i]; for (i=0;i<4;i++) raw->nav.utc_gps[i]=utc[i]; raw->nav.leaps=leaps; return 9; } } return 0; }