annotate libmpcodecs/ad_dmo.c @ 31538:09e7a988ab93

Fix resizing with -wid after previous commit.
author reimar
date Thu, 01 Jul 2010 20:00:19 +0000
parents cc27da5d7286
children 9986a61354e6
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
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
19 #include <stdio.h>
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
20 #include <stdlib.h>
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
21 #include <unistd.h>
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
22
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
23 #include "config.h"
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
24 #include "mp_msg.h"
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
25 #include "help_mp.h"
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
26
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
27 #include "ad_internal.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
28 #include "libaf/reorder_ch.h"
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
29
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
30 static const ad_info_t info =
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
31 {
8327
arpi
parents: 8326
diff changeset
32 "Win32/DMO decoders",
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
33 "dmo",
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
34 "A'rpi",
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
35 "avifile.sf.net",
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
36 ""
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
37 };
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
38
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
39 LIBAD_EXTERN(dmo)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
40
22577
a033e5519802 Include loader/ prefix in #include path everywhere.
diego
parents: 18765
diff changeset
41 #include "loader/dmo/DMO_AudioDecoder.h"
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
42
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
43 static int init(sh_audio_t *sh)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
44 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
45 return 1;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
46 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
47
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
48 static int preinit(sh_audio_t *sh_audio)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
49 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
50 DMO_AudioDecoder* ds_adec;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
51 int chans=(audio_output_channels==sh_audio->wf->nChannels) ?
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
52 audio_output_channels : (sh_audio->wf->nChannels>=2 ? 2 : 1);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
53 if(!(ds_adec=DMO_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf,chans)))
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
54 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
55 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
56 return 0;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
57 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
58 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
59 sh_audio->channels=chans;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
60 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
13427
9d0b052c4f74 setting samplesize to 2 in decoders where neccessary.
reimar
parents: 8327
diff changeset
61 sh_audio->samplesize=2;
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
62 sh_audio->audio_in_minsize=4*sh_audio->wf->nBlockAlign;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
63 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
64 sh_audio->audio_out_minsize=4*16384;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
65 sh_audio->context = ds_adec;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
66 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DMO audio codec init OK!\n");
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
67 return 1;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
68 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
69
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
70 static void uninit(sh_audio_t *sh)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
71 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
72 DMO_AudioDecoder* ds_adec = sh->context;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
73 DMO_AudioDecoder_Destroy(ds_adec);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
74 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
75
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
76 static int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
77 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
78 int skip;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
79 switch(cmd)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
80 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
81 case ADCTRL_SKIP_FRAME:
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
82 skip=sh_audio->wf->nBlockAlign;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
83 if(skip<16){
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
84 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
85 if(skip<16) skip=16;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
86 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
87 demux_read_data(sh_audio->ds,NULL,skip);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
88 return CONTROL_TRUE;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
89 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
90 return CONTROL_UNKNOWN;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
91 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
92
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
93 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
94 {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
95 DMO_AudioDecoder* ds_adec = sh_audio->context;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
96 // int len=-1;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
97 int size_in=0;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
98 int size_out=0;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
99 int srcsize=DMO_AudioDecoder_GetSrcSize(ds_adec, maxlen);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
100 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DMO says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
101 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
102 if(sh_audio->a_in_buffer_len<srcsize){
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
103 sh_audio->a_in_buffer_len+=
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
104 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
105 srcsize-sh_audio->a_in_buffer_len);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
106 }
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
107 DMO_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
108 buf,maxlen, &size_in,&size_out);
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
109 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"DMO: audio %d -> %d converted (in_buf_len=%d of %d) %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds));
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
110 if(size_in>=sh_audio->a_in_buffer_len){
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
111 sh_audio->a_in_buffer_len=0;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
112 } else {
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
113 sh_audio->a_in_buffer_len-=size_in;
15552
7867e143a557 Use memmove instead of memcpy for overlapping areas.
reimar
parents: 13427
diff changeset
114 memmove(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
115 }
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
116 if (size_out > 0 && sh_audio->channels >= 5) {
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
117 reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
118 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
119 sh_audio->channels,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
120 size_out / sh_audio->samplesize,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
121 sh_audio->samplesize);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 23918
diff changeset
122 }
8326
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
123 // len=size_out;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
124 return size_out;
4849a0cfc2aa DMO audio support (including 6ch support too)
arpi
parents:
diff changeset
125 }