Mercurial > mplayer.hg
comparison libmpdemux/demuxer.h @ 6192:f03fe2e84efd
clone_demux_packet(), using refcounting to avoid memcpy()
based on (sligtly simplified) patch by Alexander Neundorf <neundorf@dellingsoft.de>
author | arpi |
---|---|
date | Sat, 25 May 2002 22:13:23 +0000 |
parents | 68cac7ecaf05 |
children | 79b2b4c3c435 |
comparison
equal
deleted
inserted
replaced
6191:26a980dbc9a5 | 6192:f03fe2e84efd |
---|---|
49 int len; | 49 int len; |
50 float pts; | 50 float pts; |
51 off_t pos; // position in index (AVI) or file (MPG) | 51 off_t pos; // position in index (AVI) or file (MPG) |
52 unsigned char* buffer; | 52 unsigned char* buffer; |
53 int flags; // keyframe, etc | 53 int flags; // keyframe, etc |
54 int refcount; //refcounter for the master packet, if 0, buffer can be free()d | |
55 struct demux_packet_st* master; //pointer to the master packet if this one is a cloned one | |
54 struct demux_packet_st* next; | 56 struct demux_packet_st* next; |
55 } demux_packet_t; | 57 } demux_packet_t; |
56 | 58 |
57 typedef struct { | 59 typedef struct { |
58 int buffer_pos; // current buffer position | 60 int buffer_pos; // current buffer position |
59 int buffer_size; // current buffer size | 61 int buffer_size; // current buffer size |
60 unsigned char* buffer; // current buffer | 62 unsigned char* buffer; // current buffer, never free() it, always use free_demux_packet(buffer_ref); |
61 float pts; // current buffer's pts | 63 float pts; // current buffer's pts |
62 int pts_bytes; // number of bytes read after last pts stamp | 64 int pts_bytes; // number of bytes read after last pts stamp |
63 int eof; // end of demuxed stream? (true if all buffer empty) | 65 int eof; // end of demuxed stream? (true if all buffer empty) |
64 off_t pos; // position in the input stream (file) | 66 off_t pos; // position in the input stream (file) |
65 off_t dpos; // position in the demuxed stream | 67 off_t dpos; // position in the demuxed stream |
68 //--------------- | 70 //--------------- |
69 int packs; // number of packets in buffer | 71 int packs; // number of packets in buffer |
70 int bytes; // total bytes of packets in buffer | 72 int bytes; // total bytes of packets in buffer |
71 demux_packet_t *first; // read to current buffer from here | 73 demux_packet_t *first; // read to current buffer from here |
72 demux_packet_t *last; // append new packets from input stream to here | 74 demux_packet_t *last; // append new packets from input stream to here |
75 demux_packet_t *current;// needed for refcounting of the buffer | |
73 int id; // stream ID (for multiple audio/video streams) | 76 int id; // stream ID (for multiple audio/video streams) |
74 struct demuxer_st *demuxer; // parent demuxer structure (stream handler) | 77 struct demuxer_st *demuxer; // parent demuxer structure (stream handler) |
75 // ---- asf ----- | 78 // ---- asf ----- |
76 demux_packet_t *asf_packet; // read asf fragments here | 79 demux_packet_t *asf_packet; // read asf fragments here |
77 int asf_seq; | 80 int asf_seq; |
121 dp->buffer=len?malloc(len):NULL; | 124 dp->buffer=len?malloc(len):NULL; |
122 dp->next=NULL; | 125 dp->next=NULL; |
123 dp->pts=0; | 126 dp->pts=0; |
124 dp->pos=0; | 127 dp->pos=0; |
125 dp->flags=0; | 128 dp->flags=0; |
129 dp->refcount=1; | |
130 dp->master=NULL; | |
126 return dp; | 131 return dp; |
127 } | 132 } |
128 | 133 |
134 inline static demux_packet_t* clone_demux_packet(demux_packet_t* pack){ | |
135 demux_packet_t* dp=malloc(sizeof(demux_packet_t)); | |
136 while(pack->master) pack=pack->master; // find the master | |
137 memcpy(dp,pack,sizeof(demux_packet_t)); | |
138 dp->next=NULL; | |
139 dp->refcount=0; | |
140 dp->master=pack; | |
141 pack->refcount++; | |
142 return dp; | |
143 } | |
144 | |
129 inline static void free_demux_packet(demux_packet_t* dp){ | 145 inline static void free_demux_packet(demux_packet_t* dp){ |
130 free(dp->buffer); | 146 if (dp->master==NULL){ //dp is a master packet |
147 dp->refcount--; | |
148 if (dp->refcount==0){ | |
149 if (dp->buffer) free(dp->buffer); | |
150 free(dp); | |
151 } | |
152 return; | |
153 } | |
154 // dp is a clone: | |
155 free_demux_packet(dp->master); | |
131 free(dp); | 156 free(dp); |
132 } | 157 } |
133 | 158 |
134 demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id); | 159 demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id); |
135 demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id); | 160 demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id); |