void FreeUnitsArray(struct Array * arr) { for(int i = 0; i < arr->length; i++) { FreeUnit(UnitsGetUnitAtIndex(arr, i)); } //free(((struct ArrayPrivateData *)arr->privateData)->data); free(arr->data); free(arr); };
void ympg_free(void *ympgv) /* ******* Use Unref(ympg) ******* */ { ympg_stream *ympg = ympgv; /* get the delayed frames */ if (ympg->f && ympg->nframes) { if (ympg->nout) for (;;) { ympg->nout = yavc_encode_video(ympg->c, ympg->out, ympg->outsize, 0); if (!ympg->nout) break; fwrite(ympg->out, 1, ympg->nout, ympg->f); } /* add sequence end code to mpeg file */ ympg->out[0] = 0x00; ympg->out[1] = 0x00; ympg->out[2] = 0x01; ympg->out[3] = 0xb7; fwrite(ympg->out, 1, 4, ympg->f); } if (ympg->f) fclose(ympg->f); ympg->f = 0; if (ympg->c) { if (!ympg->codec) yavc_close(ympg->c); yavc_free(ympg->c); } ympg->c = 0; if (ympg->out) yavc_free(ympg->out); ympg->out = 0; if (ympg->in) yavc_free(ympg->in); ympg->in = 0; if (ympg->frame) yavc_free(ympg->frame); ympg->frame = 0; FreeUnit(&ympg_mblock, ympg); }
ympg_stream * ympg_create(char *filename, long *params) { char *name = p_native(filename); FILE *f = (name && name[0])? fopen(name, "w") : 0; ympg_stream *ympg = 0; p_free(name); if (f) { AVCodec *codec; if (params && (params[0]<0 || params[1]<0 || params[2]<0)) YError("mpeg_create: bad parameter list dimensions or values"); if (ympg_initialized != 1) { if (!yavc_convert) ympg_link(); yavc_lib_version = yavc_version(); yavc_init(); yavc_register(yavc_encoder); ympg_initialized = 1; } codec = yavc_find_encoder(CODEC_ID_MPEG1VIDEO); if (codec) { ympg = NextUnit(&ympg_mblock); ympg->references = 0; ympg->ops = &ympg_ops; ympg->f = f; ympg->c = yavc_alloc_context(); /* ffmpeg 0.4.8 bit_rate was first item in AVCodecContext */ if (yavc_lib_version < 0x000409) /* ffmpeg 0.4.8 bit_rate was first item in AVCodecContext */ ympg->c = (void *)&ympg->c->bit_rate; ympg->codec = codec; ympg->frame = yavc_alloc_frame(); ympg->in = ympg->out = 0; ympg->width = ympg->height = ympg->outsize = 0; ympg->nout = ympg->nframes = 0; if (!ympg->c || !ympg->frame) { if (ympg->c) yavc_free(ympg->c); if (ympg->frame) yavc_free(ympg->frame); FreeUnit(&ympg_mblock, ympg); ympg = 0; YError("mpeg_create: yavc_alloc_context or alloc_frame failed"); } else { ympg->c->bit_rate = (params && params[0])? params[0] : YMPG_BIT_RATE; ympg->c->frame_rate = (params && params[1])? params[1] : YMPG_FRAME_RATE; /* note c->frame_rate_base=1 by default, unnecessary for mpeg1? */ ympg->c->gop_size = (params && params[2])? params[2] : YMPG_GOP_SIZE; ympg->c->max_b_frames = (params && params[3]>=0)? params[3] : YMPG_MAX_B_FRAMES; } } else { YError("mpeg_create: failed to find MPEG1VIDEO encoder"); } } else { YError("mpeg_create: fopen failed to create mpeg output file"); } return ympg; }