view DOCS/tech/libao2.txt @ 24589:9118be6575da

demux_audio.c: Fix timestamp handling The code calculated the pts values of audio packets by adding the length of the current packet to the pts of the previous one. The length of the previous packet should be added instead. This broke WAV timestamps near the end of the stream where a short packet occurs. Change the code to store the pts of the next packet instead of the last one. This fixes the WAV timestamps and allows some simplifications. MP3 timestamps are not affected as packets are always treated as constant decoded length, and FLAC timestamps still have worse problems (FLAC is treated as as if it was constant bitrate even though it isn't). Also store the timestamps as double instead of float.
author uau
date Mon, 24 Sep 2007 21:49:56 +0000
parents 5c6111664933
children eda346733b8c
line wrap: on
line source

6. libao2: this control audio playing

  As in libvo (see 5.) also here are some drivers, based on the same API:

static int control(int cmd, int arg);
  This is for reading/setting driver-specific and other special parameters.
  Not really used for now.

static int init(int rate,int channels,int format,int flags);
  The init of driver, opens device, sets sample rate, channels, sample format
  parameters.
  Sample format: usually AFMT_S16_LE or AFMT_U8, for more definitions see
  dec_audio.c and linux/soundcards.h files!

static void uninit();
  Guess what.
  Ok I help: closes the device, not (yet) called when exit.

static void reset();
  Resets device. To be exact, it's for deleting buffers' contents,
  so after reset() the previously received stuff won't be output.
  (called if pause or seek)

static int get_space();
  Returns how many bytes can be written into the audio buffer without
  blocking (making caller process wait). MPlayer occasionally checks the
  remaining space and tries to fill the buffer with play() if there's free
  space. The buffer size used should be sane; a buffer that is too small
  could run empty before MPlayer tries filling it again (normally once per
  video frame), a buffer that is too big would force MPlayer decode the file
  far ahead trying to find enough audio data to fill it.

static int play(void* data,int len,int flags);
  Plays a bit of audio, which is received throught the "data" memory area, with
  a size of "len". It has to copy the data, because they can be overwritten
  after the call is made. Doesn't have to use all the bytes; it has to
  return the number of bytes used used (copied to buffer). If
  flags|AOPLAY_FINAL_CHUNK is true then this is the last audio in the file.
  The purpose of this flag is to tell aos that round down the audio played
  from "len" to a multiple of some chunksize that this "len" should not be
  rounded down to 0 or the data will never be played (as MPlayer will never
  call play() with a larger len).

static float get_delay(); 
  Returns how long time it will take to play the data currently in the
  output buffer. Be exact, if possible, since the whole timing depends
  on this! In the worst case, return the maximum delay.

!!! Because the video is synchronized to the audio (card), it's very important
!!! that the get_delay function is correctly implemented!

static void audio_pause(void);
  Pause playing but do not delete buffered data if possible.

static void audio_resume(void);
  Continue playing after audio_pause().