[MPlayer-dev-eng] demuxer question

Arpi arpi at thot.banki.hu
Fri May 17 12:34:06 CEST 2002


Hi,

> I'm currently writing a raw dv (as played by playdv and produced by dvgrab 
> --format raw)  demuxer and decoder using libdv for mplayer.
> Video is already working :-)

> Now I don't know exactly how to do the audio part.
> The decoding functions for audio and video of libdv both operate on the same
> buffer. Since a dv stream is quite big, it wouldn't be optimal to handle the
> stream twice through mplayer (ok, didn't test yet). 

yep... i kno wthe problem, i also starte dto work on type-2 dv .avi support
(when the avi file has one stream, having audio-video multiplexed).

imho either you should separate audio and video chunks, and hack libdv to
handle them from different buffers (or use its lowlevel functions to operate
on macroblock level), or duplicate the packet in the memory (ds_read_packet
first and then ds_new_packet and memcpy the first to that).

> Is there another way than reading the same frame twice from the file and 
> putting it into both the audio- and video "streams" (see the commented-out 
> lines) ?
nope ;(

but it is possible to implement.
the main problem is that you don't know the order of free'ing the packets.
imho with a new field in the ds packet struct it can be solved:
	int* refcount;

(sorry if func/struct names are bad, i don't have the source by hand)

for the first packet (when you malloc() the buffer), also allocate an
integer (malloc(sizeof(int)) and set refcount pointer to that.
set the value of that integer to 1.

for the clones, set the pointer to point to the same as the 'master'packet's
refcount, and increase the value.

when free'ing packets, check for refcount, and free() buffer only if
refcount was 1.

to make it a bit faster, simpler, and less memory pollution, do not allocate
the pointer at the first packet. so, assume that refcount=NULL is equal to a
pointer to value 1. when making a clone, you can malloc(sizeof(int)), and
set both packets (master and clone) to that.

i can implement this functionality, if you don't understand the above trick.


A'rpi / Astral & ESP-team

--
Developer of MPlayer, the Movie Player for Linux - http://www.MPlayerHQ.hu



More information about the MPlayer-dev-eng mailing list