annotate libmpcodecs/ad_libdv.c @ 18673:02e837b23337

Do not require iconv program with --charset=noconv
author reimar
date Sat, 10 Jun 2006 20:11:38 +0000
parents bcd805923554
children a1807995e2ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
1 #include <stdio.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
2 #include <stdlib.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
3 #include <string.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
4 #include <sys/types.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
5 #include <unistd.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
6 #include <math.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
7
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
8 #include "config.h"
18004
bcd805923554 Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents: 7180
diff changeset
9 #include "mp_msg.h"
bcd805923554 Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents: 7180
diff changeset
10 #include "help_mp.h"
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
11
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
12 #ifdef HAVE_LIBDV095
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
13
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
14 #include "img_format.h"
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
15
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
16 #include <libdv/dv.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
17 #include <libdv/dv_types.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
18
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
19 #include "stream.h"
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
20 #include "demuxer.h"
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
21 #include "stheader.h"
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
22
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
23 #include "ad_internal.h"
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
24
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
25 static ad_info_t info =
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
26 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
27 "Raw DV Audio Decoder",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
28 "libdv",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
29 "Alexander Neundorf <neundorf@kde.org>",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
30 "http://libdv.sf.net",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
31 ""
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
32 };
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
33
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
34 LIBAD_EXTERN(libdv)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
35
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
36 // defined in vd_libdv.c:
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
37 dv_decoder_t* init_global_rawdv_decoder();
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
38
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
39 static int preinit(sh_audio_t *sh_audio)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
40 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
41 sh_audio->audio_out_minsize=4*DV_AUDIO_MAX_SAMPLES*2;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
42 return 1;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
43 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
44
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
45 static int16_t *audioBuffers[4]={NULL,NULL,NULL,NULL};
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
46
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
47 static int init(sh_audio_t *sh)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
48 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
49 int i;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
50 WAVEFORMATEX *h=sh->wf;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
51
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
52 if(!h) return 0;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
53
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
54 sh->i_bps=h->nAvgBytesPerSec;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
55 sh->channels=h->nChannels;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
56 sh->samplerate=h->nSamplesPerSec;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
57 sh->samplesize=(h->wBitsPerSample+7)/8;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
58
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
59 sh->context=init_global_rawdv_decoder();
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
60
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
61 for (i=0; i < 4; i++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
62 audioBuffers[i] = malloc(2*DV_AUDIO_MAX_SAMPLES);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
63
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
64 return 1;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
65 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
66
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
67 static void uninit(sh_audio_t *sh_audio)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
68 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
69 int i;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
70 for (i=0; i < 4; i++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
71 free(audioBuffers[i]);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
72 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
73
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
74 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
75 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
76 // TODO!!!
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
77 return CONTROL_UNKNOWN;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
78 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
79
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
80 static int decode_audio(sh_audio_t *audio, unsigned char *buf, int minlen, int maxlen)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
81 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
82 int len=0;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
83 dv_decoder_t* decoder=audio->context; //global_rawdv_decoder;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
84 unsigned char* dv_audio_frame=NULL;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
85 int xx=ds_get_packet(audio->ds,&dv_audio_frame);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
86 if(xx<=0 || !dv_audio_frame) return 0; // EOF?
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
87
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
88 dv_parse_header(decoder, dv_audio_frame);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
89
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
90 if(xx!=decoder->frame_size)
18004
bcd805923554 Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents: 7180
diff changeset
91 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_MPCODECS_AudioFramesizeDiffers,
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
92 xx, decoder->frame_size);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
93
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
94 if (dv_decode_full_audio(decoder, dv_audio_frame,(int16_t**) audioBuffers))
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
95 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
96 /* Interleave the audio into a single buffer */
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
97 int i=0;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
98 int16_t *bufP=(int16_t*)buf;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
99
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
100 // printf("samples=%d/%d chans=%d mem=%d \n",decoder->audio->samples_this_frame,DV_AUDIO_MAX_SAMPLES,
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
101 // decoder->audio->num_channels, decoder->audio->samples_this_frame*decoder->audio->num_channels*2);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
102
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
103 // return (44100/30)*4;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
104
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
105 for (i=0; i < decoder->audio->samples_this_frame; i++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
106 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
107 int ch;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
108 for (ch=0; ch < decoder->audio->num_channels; ch++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
109 bufP[len++] = audioBuffers[ch][i];
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
110 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
111 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
112 return len*2;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
113 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
114
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
115 #endif
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
116