annotate libmpcodecs/ad_libdv.c @ 30927:9a9d57f6d788

Use calloc instead of malloc+memset
author reimar
date Sat, 27 Mar 2010 15:35:59 +0000
parents b2829d4f2de4
children 1b0d31ceb2ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
19 #include <stdio.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
20 #include <stdlib.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
21 #include <string.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
22 #include <sys/types.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
23 #include <unistd.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
24 #include <math.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
25
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
26 #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
27 #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
28 #include "help_mp.h"
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
29
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
30 #include "img_format.h"
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 #include <libdv/dv.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
33 #include <libdv/dv_types.h>
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
34
22599
4faee1254928 Add explicit location for headers from the stream/ directory.
diego
parents: 18771
diff changeset
35 #include "stream/stream.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22599
diff changeset
36 #include "libmpdemux/demuxer.h"
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22599
diff changeset
37 #include "libmpdemux/stheader.h"
6927
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 #include "ad_internal.h"
30553
b2829d4f2de4 Add header for init_global_rawdv_decoder() instead of forward declaring it.
diego
parents: 30504
diff changeset
40 #include "vd_libdv.h"
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
41
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
42 static const ad_info_t info =
6927
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 "Raw DV Audio Decoder",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
45 "libdv",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
46 "Alexander Neundorf <neundorf@kde.org>",
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
47 "http://libdv.sf.net",
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 };
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
50
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
51 LIBAD_EXTERN(libdv)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
52
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
53 static int preinit(sh_audio_t *sh_audio)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
54 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
55 sh_audio->audio_out_minsize=4*DV_AUDIO_MAX_SAMPLES*2;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
56 return 1;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
57 }
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 static int16_t *audioBuffers[4]={NULL,NULL,NULL,NULL};
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 static int init(sh_audio_t *sh)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
62 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
63 int i;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
64 WAVEFORMATEX *h=sh->wf;
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 if(!h) return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22886
diff changeset
67
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
68 sh->i_bps=h->nAvgBytesPerSec;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
69 sh->channels=h->nChannels;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
70 sh->samplerate=h->nSamplesPerSec;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
71 sh->samplesize=(h->wBitsPerSample+7)/8;
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 sh->context=init_global_rawdv_decoder();
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
74
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
75 for (i=0; i < 4; i++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
76 audioBuffers[i] = malloc(2*DV_AUDIO_MAX_SAMPLES);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
77
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
78 return 1;
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
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
81 static void uninit(sh_audio_t *sh_audio)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
82 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
83 int i;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
84 for (i=0; i < 4; i++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
85 free(audioBuffers[i]);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
86 }
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 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
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 // TODO!!!
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
91 return CONTROL_UNKNOWN;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
92 }
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 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
95 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
96 int len=0;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
97 dv_decoder_t* decoder=audio->context; //global_rawdv_decoder;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
98 unsigned char* dv_audio_frame=NULL;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
99 int xx=ds_get_packet(audio->ds,&dv_audio_frame);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
100 if(xx<=0 || !dv_audio_frame) return 0; // EOF?
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
101
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
102 dv_parse_header(decoder, dv_audio_frame);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22886
diff changeset
103
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
104 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
105 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_MPCODECS_AudioFramesizeDiffers,
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
106 xx, decoder->frame_size);
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
107
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
108 if (dv_decode_full_audio(decoder, dv_audio_frame,(int16_t**) audioBuffers))
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
109 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
110 /* Interleave the audio into a single buffer */
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
111 int i=0;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
112 int16_t *bufP=(int16_t*)buf;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22886
diff changeset
113
6927
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
114 // 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
115 // 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
116
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
117 // return (44100/30)*4;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
118
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
119 for (i=0; i < decoder->audio->samples_this_frame; i++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
120 {
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
121 int ch;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
122 for (ch=0; ch < decoder->audio->num_channels; ch++)
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
123 bufP[len++] = audioBuffers[ch][i];
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
124 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
125 }
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
126 return len*2;
0145bba6e201 native DV audio/video decoders using libdv
arpi
parents:
diff changeset
127 }