cache: Don't mess up current position if time-based seek fails
[mplayer/glamo.git] / libmpcodecs / ad_libdv.c
blobcbcb46efeabfbf41d46acaaa384035270d621d1b
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include <math.h>
26 #include "config.h"
27 #include "mp_msg.h"
29 #include "img_format.h"
31 #include <libdv/dv.h>
32 #include <libdv/dv_types.h>
34 #include "stream/stream.h"
35 #include "libmpdemux/demuxer.h"
36 #include "libmpdemux/stheader.h"
38 #include "ad_internal.h"
39 #include "vd_libdv.h"
41 static const ad_info_t info =
43 "Raw DV Audio Decoder",
44 "libdv",
45 "Alexander Neundorf <neundorf@kde.org>",
46 "http://libdv.sf.net",
50 LIBAD_EXTERN(libdv)
52 static int preinit(sh_audio_t *sh_audio)
54 sh_audio->audio_out_minsize=4*DV_AUDIO_MAX_SAMPLES*2;
55 return 1;
58 static int16_t *audioBuffers[4]={NULL,NULL,NULL,NULL};
60 static int init(sh_audio_t *sh)
62 int i;
63 WAVEFORMATEX *h=sh->wf;
65 if(!h) return 0;
67 sh->i_bps=h->nAvgBytesPerSec;
68 sh->channels=h->nChannels;
69 sh->samplerate=h->nSamplesPerSec;
70 sh->samplesize=(h->wBitsPerSample+7)/8;
72 sh->context=init_global_rawdv_decoder();
74 for (i=0; i < 4; i++)
75 audioBuffers[i] = malloc(2*DV_AUDIO_MAX_SAMPLES);
77 return 1;
80 static void uninit(sh_audio_t *sh_audio)
82 int i;
83 for (i=0; i < 4; i++)
84 free(audioBuffers[i]);
87 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
89 // TODO!!!
90 return CONTROL_UNKNOWN;
93 static int decode_audio(sh_audio_t *audio, unsigned char *buf, int minlen, int maxlen)
95 int len=0;
96 dv_decoder_t* decoder=audio->context; //global_rawdv_decoder;
97 unsigned char* dv_audio_frame=NULL;
98 int xx=ds_get_packet(audio->ds,&dv_audio_frame);
99 if(xx<=0 || !dv_audio_frame) return 0; // EOF?
101 dv_parse_header(decoder, dv_audio_frame);
103 if(xx!=decoder->frame_size)
104 mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[AD_LIBDV] Warning! Audio framesize differs! read=%d hdr=%d.\n",
105 xx, decoder->frame_size);
107 if (dv_decode_full_audio(decoder, dv_audio_frame,(int16_t**) audioBuffers))
109 /* Interleave the audio into a single buffer */
110 int i=0;
111 int16_t *bufP=(int16_t*)buf;
113 // printf("samples=%d/%d chans=%d mem=%d \n",decoder->audio->samples_this_frame,DV_AUDIO_MAX_SAMPLES,
114 // decoder->audio->num_channels, decoder->audio->samples_this_frame*decoder->audio->num_channels*2);
116 // return (44100/30)*4;
118 for (i=0; i < decoder->audio->samples_this_frame; i++)
120 int ch;
121 for (ch=0; ch < decoder->audio->num_channels; ch++)
122 bufP[len++] = audioBuffers[ch][i];
125 return len*2;