void CMpeg2Decoder::Close() { if (m_pDec) { mpeg2_close(m_pDec); m_pDec = nullptr; } }
PrivateDecoderMPEG2::~PrivateDecoderMPEG2() { if (mpeg2dec) mpeg2_close(mpeg2dec); mpeg2dec = NULL; ClearFrames(); }
static void sample1 (FILE * file) { #define BUFFER_SIZE 4096 uint8_t buffer[BUFFER_SIZE]; mpeg2dec_t * mpeg2dec; const mpeg2_info_t * info; int state; int size; int framenum = 0; mpeg2dec = mpeg2_init (); if (mpeg2dec == NULL) exit (1); info = mpeg2_info (mpeg2dec); size = BUFFER_SIZE; do { state = mpeg2_parse (mpeg2dec); switch (state) { case -1: size = fread (buffer, 1, BUFFER_SIZE, file); mpeg2_buffer (mpeg2dec, buffer, buffer + size); break; case STATE_SLICE: case STATE_END: if (info->display_fbuf) save_pgm (info->sequence->width, info->sequence->height, info->display_fbuf->buf, framenum++); break; } } while (size); mpeg2_close (mpeg2dec); }
MPEGDecoder::~MPEGDecoder() { mpeg2_close(_mpegDecoder); if (_surface) { _surface->free(); delete _surface; } }
void mpeg_free(mpeg_struct_t *Mpeg_Struct) { if(!Mpeg_Struct) return; if(Mpeg_Struct) { mpeg2_close (Mpeg_Struct->decoder); Mpeg_Struct = 0; } }
void decode_mpeg2(decode_t *decode) { mpeg2dec_t *decoder = NULL; const mpeg2_info_t *info = NULL; const mpeg2_sequence_t *sequence = NULL; mpeg2_state_t state; size_t size; uint32_t ac = 0; WriteDataFn writer = write_yuv420p; if (decode->format == TC_CODEC_RGB) { tc_log_info(__FILE__, "using libmpeg2convert" " RGB24 conversion"); writer = write_rgb24; } ac = mpeg2_accel(MPEG2_ACCEL_DETECT); show_accel(ac); decoder = mpeg2_init(); if (decoder == NULL) { tc_log_error(__FILE__, "Could not allocate a decoder object."); import_exit(1); } info = mpeg2_info(decoder); size = (size_t)-1; do { state = mpeg2_parse(decoder); sequence = info->sequence; switch (state) { case STATE_BUFFER: size = tc_pread(decode->fd_in, buffer, BUFFER_SIZE); mpeg2_buffer(decoder, buffer, buffer + size); break; case STATE_SEQUENCE: if (decode->format == TC_CODEC_RGB) { mpeg2_convert(decoder, mpeg2convert_rgb24, NULL); } break; case STATE_SLICE: case STATE_END: case STATE_INVALID_END: if (info->display_fbuf) { writer(decode, info, sequence); } break; default: /* can't happen */ break; } } while (size); mpeg2_close(decoder); import_exit(0); }
int closempeg2(void) { if (global_mpegfile==NULL) return 1; /* close the mpeg decoder */ if (decoder!=NULL) mpeg2_close(decoder); decoder=NULL; fclose(global_mpegfile); global_mpegfile=NULL; return 1; }
static void mpeg2dec_close (codec_data_t *ifptr) { mpeg2dec_codec_t *mpeg2dec; mpeg2dec = (mpeg2dec_codec_t *)ifptr; if (mpeg2dec->m_decoder) { mpeg2_close(mpeg2dec->m_decoder); mpeg2dec->m_decoder = NULL; } free(mpeg2dec); }
void TvideoCodecLibmpeg2::end(void) { if (mpeg2dec) { mpeg2_close(mpeg2dec); } mpeg2dec=NULL; if (quants) { free(quants); } quants=NULL; }
int rewindmpeg2(void) { if (global_mpegfile==NULL) return 1; /* close the mpeg decoder */ if (decoder!=NULL) mpeg2_close(decoder); decoder=NULL; /* rewind the old mpgfile if opened */ if (global_mpegfile!=NULL) rewind(global_mpegfile); /* reinitialize the mpeg decoder */ return _initmpeg2(global_mpegfile,NULL,NULL); }
BaseAnimationState::~BaseAnimationState() { #ifdef USE_MPEG2 if (_mpegDecoder) mpeg2_close(_mpegDecoder); delete _mpegFile; #ifndef BACKEND_8BIT _sys->hideOverlay(); free(_overlay); free(_colorTab); free(_rgbToPix); #endif #endif }
// ----------------------------------------------------------------------------- // Destructor // ----------------------------------------------------------------------------- TTMpeg2Decoder::~TTMpeg2Decoder() { mpeg2_close( mpeg2Decoder ); if ( ttAssigned(mpeg2Stream) ) { mpeg2Stream->closeFile(); delete mpeg2Stream; } if ( ttAssigned(streamBuffer) ) delete streamBuffer; }
static gboolean gst_mpeg2dec_close (GstVideoDecoder * decoder) { GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (decoder); if (mpeg2dec->decoder) { mpeg2_close (mpeg2dec->decoder); mpeg2dec->decoder = NULL; mpeg2dec->info = NULL; } gst_mpeg2dec_clear_buffers (mpeg2dec); return TRUE; }
static void gst_mpeg2dec_finalize (GObject * object) { GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (object); if (mpeg2dec->decoder) { GST_DEBUG_OBJECT (mpeg2dec, "closing decoder"); mpeg2_close (mpeg2dec->decoder); mpeg2dec->decoder = NULL; } gst_mpeg2dec_clear_buffers (mpeg2dec); g_free (mpeg2dec->dummybuf[3]); mpeg2dec->dummybuf[3] = NULL; G_OBJECT_CLASS (parent_class)->finalize (object); }
//____________________-un init ____________________ uint8_t decoderMpeg::kill_codec (void) { decoder_t *dec; dec=&((MPEG2DEC)->decoder); if(dec->quant) { free(dec->quant); dec->quant=NULL; } mpeg2_close (MPEG2DEC); _decoder=NULL; yv12_close (output); deletePostProc(&_postproc); return 1; }
bool PrivateDecoderMPEG2::Init(const QString &decoder, bool no_hardware_decode, AVCodecContext *avctx) { if (!((decoder == "libmpeg2") && (CODEC_IS_MPEG(avctx->codec_id)))) return false; if (mpeg2dec) mpeg2_close(mpeg2dec); ClearFrames(); mpeg2dec = mpeg2_init(); if (mpeg2dec) { VERBOSE(VB_PLAYBACK, LOC + "Using libmpeg2 for video decoding"); return true; } return false; }
static void sample2 (FILE * mpgfile) { #define BUFFER_SIZE 4096 uint8_t buffer[BUFFER_SIZE]; mpeg2dec_t * decoder; const mpeg2_info_t * info; mpeg2_state_t state; size_t size; int framenum = 0; decoder = mpeg2_init (); if (decoder == NULL) { fprintf (stderr, "Could not allocate a decoder object.\n"); exit (1); } info = mpeg2_info (decoder); size = (size_t)-1; do { state = mpeg2_parse (decoder); switch (state) { case STATE_BUFFER: size = fread (buffer, 1, BUFFER_SIZE, mpgfile); mpeg2_buffer (decoder, buffer, buffer + size); break; case STATE_SEQUENCE: mpeg2_convert (decoder, mpeg2convert_rgb24, NULL); break; case STATE_SLICE: case STATE_END: case STATE_INVALID_END: if (info->display_fbuf) save_ppm (info->sequence->width, info->sequence->height, info->display_fbuf->buf[0], framenum++); break; default: break; } } while (size); mpeg2_close (decoder); }
/***************************************************************************** * RunDecoder: the libmpeg2 decoder *****************************************************************************/ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; mpeg2_state_t state; picture_t *p_pic; block_t *p_block; if( !pp_block || !*pp_block ) return NULL; p_block = *pp_block; if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) ) { cc_Flush( &p_sys->cc ); mpeg2_reset( p_sys->p_mpeg2dec, p_sys->p_info->sequence != NULL ); DpbClean( p_dec ); } while( 1 ) { state = mpeg2_parse( p_sys->p_mpeg2dec ); switch( state ) { case STATE_SEQUENCE: { /* */ DpbClean( p_dec ); /* */ mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 ); /* Set the first 2 reference frames */ GetAR( p_dec ); for( int i = 0; i < 2; i++ ) { picture_t *p_picture = DpbNewPicture( p_dec ); if( !p_picture ) { /* Is it ok ? or do we need a reset ? */ block_Release( p_block ); return NULL; } PutPicture( p_dec, p_picture ); } if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro ); p_sys->p_synchro = decoder_SynchroInit( p_dec, (uint32_t)((uint64_t)1001000000 * 27 / p_sys->p_info->sequence->frame_period) ); p_sys->b_after_sequence_header = true; break; } case STATE_GOP: /* There can be userdata in a GOP. It needs to be remembered for the next picture. */ if( p_sys->p_info->user_data_len > 2 ) { free( p_sys->p_gop_user_data ); p_sys->p_gop_user_data = calloc( p_sys->p_info->user_data_len, sizeof(uint8_t) ); if( p_sys->p_gop_user_data ) { p_sys->i_gop_user_data = p_sys->p_info->user_data_len; memcpy( p_sys->p_gop_user_data, p_sys->p_info->user_data, p_sys->p_info->user_data_len ); } } break; case STATE_PICTURE: { const mpeg2_info_t *p_info = p_sys->p_info; const mpeg2_picture_t *p_current = p_info->current_picture; mtime_t i_pts, i_dts; if( p_sys->b_after_sequence_header && (p_current->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P ) { /* Intra-slice refresh. Simulate a blank I picture. */ msg_Dbg( p_dec, "intra-slice refresh stream" ); decoder_SynchroNewPicture( p_sys->p_synchro, I_CODING_TYPE, 2, 0, 0, p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ); decoder_SynchroDecode( p_sys->p_synchro ); decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 ); p_sys->b_slice_i = true; } p_sys->b_after_sequence_header = false; #ifdef PIC_FLAG_PTS i_pts = p_current->flags & PIC_FLAG_PTS ? ( ( p_current->pts == (uint32_t)p_sys->i_current_pts ) ? p_sys->i_current_pts : p_sys->i_previous_pts ) : 0; i_dts = 0; /* Hack to handle demuxers which only have DTS timestamps */ if( !i_pts && !p_block->i_pts && p_block->i_dts > 0 ) { if( p_info->sequence->flags & SEQ_FLAG_LOW_DELAY || (p_current->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B ) { i_pts = p_block->i_dts; } } p_block->i_pts = p_block->i_dts = 0; /* End hack */ #else /* New interface */ i_pts = p_current->flags & PIC_FLAG_TAGS ? ( ( p_current->tag == (uint32_t)p_sys->i_current_pts ) ? p_sys->i_current_pts : p_sys->i_previous_pts ) : 0; i_dts = p_current->flags & PIC_FLAG_TAGS ? ( ( p_current->tag2 == (uint32_t)p_sys->i_current_dts ) ? p_sys->i_current_dts : p_sys->i_previous_dts ) : 0; #endif /* If nb_fields == 1, it is a field picture, and it will be * followed by another field picture for which we won't call * decoder_SynchroNewPicture() because this would have other * problems, so we take it into account here. * This kind of sucks, but I didn't think better. --Meuuh */ decoder_SynchroNewPicture( p_sys->p_synchro, p_current->flags & PIC_MASK_CODING_TYPE, p_current->nb_fields == 1 ? 2 : p_current->nb_fields, i_pts, i_dts, p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ); bool b_skip = false; if( !p_dec->b_pace_control && !p_sys->b_preroll && !(p_sys->b_slice_i && ((p_current->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P)) && !decoder_SynchroChoose( p_sys->p_synchro, p_current->flags & PIC_MASK_CODING_TYPE, /*p_sys->p_vout->render_time*/ 0 /*FIXME*/, p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) ) { b_skip = true; } p_pic = NULL; if( !b_skip ) p_pic = DpbNewPicture( p_dec ); if( b_skip || !p_pic ) { mpeg2_skip( p_sys->p_mpeg2dec, 1 ); p_sys->b_skip = true; decoder_SynchroTrash( p_sys->p_synchro ); PutPicture( p_dec, NULL ); if( !b_skip ) { block_Release( p_block ); return NULL; } } else { mpeg2_skip( p_sys->p_mpeg2dec, 0 ); p_sys->b_skip = false; decoder_SynchroDecode( p_sys->p_synchro ); PutPicture( p_dec, p_pic ); } if( p_info->user_data_len > 2 || p_sys->i_gop_user_data > 2 ) { p_sys->i_cc_pts = i_pts; p_sys->i_cc_dts = i_dts; if( (p_current->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P ) p_sys->i_cc_flags = BLOCK_FLAG_TYPE_P; else if( (p_current->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B ) p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B; else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I; if( p_sys->i_gop_user_data > 2 ) { /* We now have picture info for any cached user_data out of the gop */ cc_Extract( &p_sys->cc, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data ); p_sys->i_gop_user_data = 0; } /* Extract the CC from the user_data of the picture */ if( p_info->user_data_len > 2 ) cc_Extract( &p_sys->cc, &p_info->user_data[0], p_info->user_data_len ); } } break; case STATE_BUFFER: if( !p_block->i_buffer ) { block_Release( p_block ); return NULL; } if( (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED)) && p_sys->p_synchro && p_sys->p_info->sequence && p_sys->p_info->sequence->width != (unsigned)-1 ) { decoder_SynchroReset( p_sys->p_synchro ); if( p_sys->p_info->current_fbuf != NULL && p_sys->p_info->current_fbuf->id != NULL ) { p_sys->b_garbage_pic = true; } if( p_sys->b_slice_i ) { decoder_SynchroNewPicture( p_sys->p_synchro, I_CODING_TYPE, 2, 0, 0, p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ); decoder_SynchroDecode( p_sys->p_synchro ); decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 ); } } if( p_block->i_flags & BLOCK_FLAG_PREROLL ) { p_sys->b_preroll = true; } else if( p_sys->b_preroll ) { p_sys->b_preroll = false; if( p_sys->p_synchro ) decoder_SynchroReset( p_sys->p_synchro ); } #ifdef PIC_FLAG_PTS if( p_block->i_pts ) { mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts ); #else /* New interface */ if( p_block->i_pts || p_block->i_dts ) { mpeg2_tag_picture( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts, (uint32_t)p_block->i_dts ); #endif p_sys->i_previous_pts = p_sys->i_current_pts; p_sys->i_current_pts = p_block->i_pts; p_sys->i_previous_dts = p_sys->i_current_dts; p_sys->i_current_dts = p_block->i_dts; } mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer, p_block->p_buffer + p_block->i_buffer ); p_block->i_buffer = 0; break; #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0) case STATE_SEQUENCE_MODIFIED: GetAR( p_dec ); break; #endif case STATE_PICTURE_2ND: p_sys->b_second_field = true; break; case STATE_INVALID_END: case STATE_END: case STATE_SLICE: p_pic = NULL; if( p_sys->p_info->display_fbuf && p_sys->p_info->display_fbuf->id ) { p_pic = p_sys->p_info->display_fbuf->id; DpbDisplayPicture( p_dec, p_pic ); decoder_SynchroEnd( p_sys->p_synchro, p_sys->p_info->display_picture->flags & PIC_MASK_CODING_TYPE, p_sys->b_garbage_pic ); p_pic->date = decoder_SynchroDate( p_sys->p_synchro ); if( p_sys->b_garbage_pic ) p_pic->date = 0; /* ??? */ p_sys->b_garbage_pic = false; } if( p_sys->p_info->discard_fbuf && p_sys->p_info->discard_fbuf->id ) { DpbUnlinkPicture( p_dec, p_sys->p_info->discard_fbuf->id ); } /* For still frames */ if( state == STATE_END && p_pic ) p_pic->b_force = true; if( p_pic ) { /* Avoid frames with identical timestamps. * Especially needed for still frames in DVD menus. */ if( p_sys->i_last_frame_pts == p_pic->date ) p_pic->date++; p_sys->i_last_frame_pts = p_pic->date; return p_pic; } break; case STATE_INVALID: { msg_Err( p_dec, "invalid picture encountered" ); /* I don't think we have anything to do, but well without * docs ... */ break; } default: break; } } /* Never reached */ return NULL; } /***************************************************************************** * CloseDecoder: libmpeg2 decoder destruction *****************************************************************************/ static void CloseDecoder( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t *)p_this; decoder_sys_t *p_sys = p_dec->p_sys; DpbClean( p_dec ); free( p_sys->p_gop_user_data ); if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro ); if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec ); free( p_sys ); }
static void sample5 (FILE * mpgfile) { #define BUFFER_SIZE 4096 #define ALIGN_16(p) ((void *)(((uintptr_t)(p) + 15) & ~((uintptr_t)15))) uint8_t buffer[BUFFER_SIZE]; mpeg2dec_t * decoder; const mpeg2_info_t * info; const mpeg2_sequence_t * sequence; mpeg2_state_t state; size_t size; int framenum = 0; int i, j; struct fbuf_s * current_fbuf; decoder = mpeg2_init (); if (decoder == NULL) { fprintf (stderr, "Could not allocate a decoder object.\n"); exit (1); } info = mpeg2_info (decoder); size = (size_t)-1; do { state = mpeg2_parse (decoder); sequence = info->sequence; switch (state) { case STATE_BUFFER: size = fread (buffer, 1, BUFFER_SIZE, mpgfile); mpeg2_buffer (decoder, buffer, buffer + size); break; case STATE_SEQUENCE: mpeg2_custom_fbuf (decoder, 1); for (i = 0; i < 3; i++) { fbuf[i].mbuf[0] = (uint8_t *) malloc (sequence->width * sequence->height + 15); fbuf[i].mbuf[1] = (uint8_t *) malloc (sequence->chroma_width * sequence->chroma_height + 15); fbuf[i].mbuf[2] = (uint8_t *) malloc (sequence->chroma_width * sequence->chroma_height + 15); if (!fbuf[i].mbuf[0] || !fbuf[i].mbuf[1] || !fbuf[i].mbuf[2]) { fprintf (stderr, "Could not allocate an output buffer.\n"); exit (1); } for (j = 0; j < 3; j++) fbuf[i].yuv[j] = ALIGN_16 (fbuf[i].mbuf[j]); fbuf[i].used = 0; } for (i = 0; i < 2; i++) { current_fbuf = get_fbuf (); mpeg2_set_buf (decoder, current_fbuf->yuv, current_fbuf); } break; case STATE_PICTURE: current_fbuf = get_fbuf (); mpeg2_set_buf (decoder, current_fbuf->yuv, current_fbuf); break; case STATE_SLICE: case STATE_END: case STATE_INVALID_END: if (info->display_fbuf) save_pgm (sequence->width, sequence->height, sequence->chroma_width, sequence->chroma_height, info->display_fbuf->buf, framenum++); if (info->discard_fbuf) ((struct fbuf_s *)info->discard_fbuf->id)->used = 0; if (state != STATE_SLICE) for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) free (fbuf[i].mbuf[j]); break; default: break; } } while (size); mpeg2_close (decoder); }
void glueMpeg2_close(Mpeg2 *mpg) { if (mpg->stream_from_disk) fclose(mpg->f); mpeg2_close(mpg->decoder); }
static void sample3 (FILE * mpgfile) { #define BUFFER_SIZE 4096 uint8_t buffer[BUFFER_SIZE]; mpeg2dec_t * decoder; const mpeg2_info_t * info; const mpeg2_sequence_t * sequence; mpeg2_state_t state; size_t size; int framenum = 0; uint8_t * fbuf[3][3]; int i, j; decoder = mpeg2_init (); if (decoder == NULL) { fprintf (stderr, "Could not allocate a decoder object.\n"); exit (1); } info = mpeg2_info (decoder); size = (size_t)-1; do { state = mpeg2_parse (decoder); sequence = info->sequence; switch (state) { case STATE_BUFFER: size = fread (buffer, 1, BUFFER_SIZE, mpgfile); mpeg2_buffer (decoder, buffer, buffer + size); break; case STATE_SEQUENCE: for (i = 0; i < 3; i++) { fbuf[i][0] = (uint8_t *) malloc (sequence->width * sequence->height); fbuf[i][1] = (uint8_t *) malloc (sequence->chroma_width * sequence->chroma_height); fbuf[i][2] = (uint8_t *) malloc (sequence->chroma_width * sequence->chroma_height); if (!fbuf[i][0] || !fbuf[i][1] || !fbuf[i][2]) { fprintf (stderr, "Could not allocate an output buffer.\n"); exit (1); } mpeg2_set_buf (decoder, fbuf[i], NULL); } break; case STATE_SLICE: case STATE_END: case STATE_INVALID_END: if (info->display_fbuf) save_pgm (sequence->width, sequence->height, sequence->chroma_width, sequence->chroma_height, info->display_fbuf->buf, framenum++); if (state != STATE_SLICE) for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) free (fbuf[i][j]); break; default: break; } } while (size); mpeg2_close (decoder); }
// FIXME: maybe mmap isn't such a good idea for giant files? int main(int argc, char *argv[]) { int i, out, count; MPEG2Parser *mpeg2parser; // check for our arguments #ifdef WRITEOUT if (argc < 3) { fprintf(stderr, _("Usage: %s INPUT OUTPUT\n"), argv[0]); exit(1); } #else // WRITEOUT if (argc < 2) { fprintf(stderr, _("Usage: %s INPUT\n"), argv[0]); exit(1); } #endif // WRITEOUT decode_init(); mpeg2parser = new MPEG2Parser(); if (!mpeg2parser->init(argv[1], ticker)) { fprintf(stderr, "%s\n", mpeg2parser->getError()); exit(1); } mpeg2parser->parse(); if (mpeg2parser->getError()) fprintf(stderr, "%s\n", mpeg2parser->getError()); #ifdef WRITEOUT // open our output file for writing if ((out = open(argv[2], O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) { perror(argv[2]); exit(1); } #endif // WRITEOUT List *GOPs = mpeg2parser->getGOPs(); printf(_("GOPs: %d\n"), GOPs->getNum()); #ifdef RENDEROUT int GOPmax = GOPs->getNum(); for (i = 0; i < GOPmax; i++) { Pack *packet; GroupOfPictures *GOP; Bounds *bounds; ElementStream *ves; int start, stop; int ves_start, ves_stop; uint8_t *loc; size_t len; ticker(_("Rendering GOPs"), (float) ((float) i / (float) GOPmax)); GOP = (GroupOfPictures *) GOPs->vector(i); bounds = GOP->getPacketBounds(); start = bounds->getFirst(); stop = bounds->getMax(); for (int j = start; j < stop; j++) { if (!(packet = (Pack *) mpeg2parser->getPackets()->vector(j))) { printf("%s", _("NULL packet?!\n")); exit(1); } ves_start = packet->getVideoFirst(); ves_stop = packet->getVideoMax(); #ifdef WRITEOUT /* write packets to disk */ if (loc = mpeg2parser->bytesAvail(packet->getStart(), packet->getLen())) { write(out, loc, packet->getLen()); } else printf("%s", _("NULL vector area?!\n")); #endif // WRITEOUT for (int k = ves_start; k < ves_stop; k++) { if (! (ves = (ElementStream *) mpeg2parser->getVideo()->vector(k))) { printf("%s", _("NULL ves?!\n")); exit(1); } #ifdef WATCHOUT len = ves->getLen(); (void *) loc = mpeg2parser->bytesAvail(ves->getStart(), len); if (loc && len) { printf("%" OFF_T_FORMAT ": %ld\n", ves->getStart(), len); fflush(NULL); mpeg2_decode_data(&mpeg2dec, loc, loc + len); } #endif // WATCHOUT } } } ticker("Rendering GOPs", 1.0); #endif // RENDEROUT /* printf("%s",_("dumping audio ES...\n")); for (i=0;i<audio_list->getNum();i++) { ElementStream * audio; if (!(audio=(ElementStream*)audio_list->vector(i))) { Error("NULL audio vector?!"); exit(1); } write(out,audio->getStart(),audio->getLen()); } // close outfile close(out); */ /* char user[512]; printf(_("view GOPs avail: 0-%d\n"),pack_list->getNum()-1); printf("%s",_("Dump which GOP? ")); fflush(NULL); while (fgets(user,512,stdin)) { int which; int first, last; which=atoi(user); if (which<pack_list->getNum()) { Pack * pack; ElementStream * video; if ((pack=(Pack*)pack_list->vector(which))) { first=pack->getMin(); last=pack->getMax(); printf(_("Showing ES %d to %d...\n"), first,last); for (i=first;i<last;i++) { if ((video=(ElementStream*)video_list->vector(i))) { mpeg2_decode_data(&mpeg2dec, video->getStart(), video->getStart()+ video->getLen()); } else Error("ES not found"); } } else Error("Pack not found"); } printf("%s",_("Dump which GOP? ")); fflush(NULL); } */ #ifdef WRITEOUT close(out); #endif #if 0 printf("%s", _("press enter to quit...")); fflush(NULL); char userin[128]; fgets(userin, 128, stdin); #endif // shutdown decoder mpeg2_close(&mpeg2dec); vo_close(output); // shutdown parser delete mpeg2parser; return 0; }
static int _initmpeg2(FILE *mpgfile,int *w, int *h) { static uint8_t buffer[BUFFER_SIZE]; mpeg2_state_t state; struct fbuf_s * current_fbuf; size_t size; int pixels; int i; global_mpegfile=mpgfile; if (decoder!=NULL) { mpeg2_close (decoder); decoder=NULL; } decoder = mpeg2_init (); if (decoder == NULL) { fprintf (stderr, "Could not allocate a decoder object.\n"); exit (1); } info = mpeg2_info (decoder); size = (size_t)-1; do { state = mpeg2_parse (decoder); if (state==STATE_BUFFER) { //fprintf(stderr,"Got STATE_BUFFER\n"); size = fread (buffer, 1, BUFFER_SIZE, global_mpegfile); mpeg2_buffer (decoder, buffer, buffer + size); } else if (state==STATE_SEQUENCE) { //fprintf(stderr,"Got STATE_SEQUENCE\n"); mpeg2_convert (decoder, mpeg2convert_rgb24, NULL); mpeg2_custom_fbuf (decoder, 1); if (w!=NULL) *w=info->sequence->width; if (h!=NULL) *h=info->sequence->height; pixels = info->sequence->width * info->sequence->height; for (i = 0; i < 3; i++) { fbuf[i].rgb[0] = (uint8_t *) malloc (3 * pixels); fbuf[i].rgb[1] = fbuf[i].rgb[2] = NULL; if (!fbuf[i].rgb[0]) { fprintf (stderr, "Could not allocate an output buffer.\n"); exit (1); } fbuf[i].used = 0; } for (i = 0; i < 2; i++) { current_fbuf = get_fbuf (); mpeg2_set_buf (decoder, current_fbuf->rgb, current_fbuf); } break; } else if (state==STATE_PICTURE || state==STATE_SLICE || state==STATE_END || state==STATE_INVALID_END) { //if (state==STATE_SLICE) fprintf(stderr,"Got STATE_PICTURE\n"); //if (state==STATE_SLICE) fprintf(stderr,"Got STATE_SLICE\n"); //if (state==STATE_END) fprintf(stderr,"Got STATE_END\n"); //if (state==STATE_INVALID_END) fprintf(stderr,"Got STATE_INVALID_END\n"); fprintf(stderr,"GOT unexpected state during initialization.\n"); return 0; } } while (size); return 1; }