Skip to content

Commit

Permalink
mencoder.c/muxer.c: add functions to close and free muxer.
Browse files Browse the repository at this point in the history
Makes behaviour clearer than mencoder using
low-level functions directly and frees some
more memory before exit to make leaks easier
to spot.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@38399 b3059339-0415-0410-9bf9-f77b7e298cf2
  • Loading branch information
reimar committed Aug 30, 2022
1 parent 950dd79 commit 63f07c6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
28 changes: 28 additions & 0 deletions libmpdemux/muxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ muxer_t *muxer_new_muxer(int type,stream_t *stream){
return NULL;
}

off_t muxer_close(muxer_t *muxer)
{
off_t size;
/* flush muxer just in case, this is a no-op unless
* we created a stream but never wrote frames to it... */
muxer_flush(muxer);
if (muxer->cont_write_index) muxer_write_index(muxer);
size=stream_tell(muxer->stream);
stream_seek(muxer->stream,0);
if (muxer->cont_write_header) muxer_write_header(muxer); // update header
return size;
}

void muxer_free(muxer_t *muxer)
{
int num;
for (num = 0; muxer->streams[num]; ++num) {
free(muxer->streams[num]->priv);
muxer->streams[num]->priv = NULL;
free(muxer->streams[num]);
muxer->streams[num] = NULL;
}
free(muxer->idx);
muxer->idx = NULL;
muxer->idx_size = 0;
free(muxer);
}

/* Flush the internal muxer buffer.
* This is normally called from muxer_write_chunk() once all streams
* have seen frames. */
Expand Down
2 changes: 2 additions & 0 deletions libmpdemux/muxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ extern const m_option_t mpegopts_conf[];
extern const m_option_t nuvopts_conf[];

muxer_t *muxer_new_muxer(int type,stream_t *stream);
off_t muxer_close(muxer_t *muxer);
void muxer_free(muxer_t *muxer);
void muxer_flush(muxer_t *m);
#define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a)
#define muxer_stream_fix_parameters(muxer, a) muxer->fix_stream_parameters(a)
Expand Down
11 changes: 4 additions & 7 deletions mencoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1699,13 +1699,7 @@ if(aencoder)
if(aencoder->fixup)
aencoder->fixup(aencoder);

/* flush muxer just in case, this is a no-op unless
* we created a stream but never wrote frames to it... */
muxer_flush(muxer);
if (muxer->cont_write_index) muxer_write_index(muxer);
muxer_f_size=stream_tell(muxer->stream);
stream_seek(muxer->stream,0);
if (muxer->cont_write_header) muxer_write_header(muxer); // update header
muxer_f_size=muxer_close(muxer);
#if 0
if(ferror(muxer_f) || fclose(muxer_f) != 0) {
mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile, out_filename);
Expand All @@ -1730,6 +1724,9 @@ if(sh_audio)
mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_AudioStreamResult,
(float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), (uint64_t)mux_a->size, (float)mux_a->timer);

muxer_free(muxer);
muxer=NULL;
mux_v=mux_a=NULL;
m_config_free(mconfig);
m_entry_list_free(filelist);
if(sh_audio){ uninit_audio(sh_audio);sh_audio=NULL; }
Expand Down

0 comments on commit 63f07c6

Please sign in to comment.