Mercurial > mplayer.hg
annotate libmpcodecs/ad_hwmpa.c @ 18794:42001f5086d2
new RTSP demuxer dedicated file, based on old code from realrtsp one but intended to be much more generic
author | ben |
---|---|
date | Fri, 23 Jun 2006 20:17:12 +0000 |
parents | 2e20dd653147 |
children | a8e681ad7c90 |
rev | line source |
---|---|
17397
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
1 #include <stdio.h> |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
2 #include <stdlib.h> |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
3 #include <string.h> |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
4 #include <unistd.h> |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
5 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
6 #include "config.h" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
7 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
8 #include "mp_msg.h" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
9 #include "help_mp.h" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
10 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
11 #include "libaf/af_format.h" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
12 #include "ad_internal.h" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
13 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
14 #include "libmpdemux/mp3_hdr.h" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
15 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
16 //based on ad_hwac3.c and ad_libmad.c |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
17 static int isdts = -1; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
18 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
19 static ad_info_t info = |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
20 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
21 "MPEG audio pass-through (fake decoder)", |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
22 "hwmpa", |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
23 "NicoDVB", |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
24 "NicoDVB", |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
25 "For hardware decoders" |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
26 }; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
27 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
28 LIBAD_EXTERN(hwmpa) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
29 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
30 static int mpa_sync(sh_audio_t *sh, int no_frames, int *n, int *chans, int *srate, int *spf, int *mpa_layer, int *br) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
31 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
32 int cnt = 0, x = 0, len, frames_count; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
33 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
34 frames_count = 0; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
35 do |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
36 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
37 while(cnt + 4 < sh->a_in_buffer_len) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
38 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
39 if(((sh->a_in_buffer[cnt] << 8) | sh->a_in_buffer[cnt+1]) & 0xffe0 != 0xffe0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
40 continue; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
41 x = mp_get_mp3_header(&(sh->a_in_buffer[cnt]), chans, srate, spf, mpa_layer, br); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
42 if(x > 0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
43 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
44 frames_count++; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
45 if(frames_count == no_frames) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
46 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
47 *n = x; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
48 return cnt; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
49 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
50 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
51 cnt++; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
52 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
53 len = demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],sh->a_in_buffer_size-sh->a_in_buffer_len); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
54 if(len > 0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
55 sh->a_in_buffer_len += len; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
56 } while(len > 0); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
57 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Cannot sync MPA frame: %d\r\n", len); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
58 return -1; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
59 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
60 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
61 static int preinit(sh_audio_t *sh) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
62 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
63 sh->audio_out_minsize = 48;//check |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
64 sh->audio_in_minsize = 4608;//check |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
65 sh->sample_format = AF_FORMAT_MPEG2; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
66 return 1; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
67 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
68 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
69 static int init(sh_audio_t *sh) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
70 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
71 int cnt, chans, srate, spf, mpa_layer, br, len; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
72 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
73 if((cnt = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br)) < 0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
74 return 0; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
75 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
76 sh->channels = chans; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
77 sh->samplerate = srate; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
78 sh->i_bps = br * 125; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
79 sh->samplesize = 2; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
80 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
81 mp_msg(MSGT_DECAUDIO,MSGL_V,"AC_HWMPA initialized, bitrate: %d kb/s\r\n", len); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
82 return 1; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
83 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
84 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
85 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
86 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
87 int len, start, cnt2, tot; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
88 int chans, srate, spf, mpa_layer, br; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
89 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
90 tot = cnt2 = 0; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
91 while(tot < minlen && tot+4608<=maxlen) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
92 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
93 start = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
94 if(start < 0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
95 break; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
96 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
97 if(start + len < sh->a_in_buffer_len && start + len >= maxlen) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
98 break; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
99 memcpy(&buf[cnt2], &(sh->a_in_buffer[start]), len); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
100 cnt2 += len; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
101 sh->a_in_buffer_len -= start + len; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
102 memmove(sh->a_in_buffer, &(sh->a_in_buffer[start + len]), sh->a_in_buffer_len); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
103 tot += start + len; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
104 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
105 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
106 return tot; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
107 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
108 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
109 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
110 static int control(sh_audio_t *sh,int cmd,void* arg, ...) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
111 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
112 int start, len, n; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
113 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
114 switch(cmd) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
115 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
116 case ADCTRL_RESYNC_STREAM: |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
117 if(mpa_sync(sh, 1, &len, NULL, NULL, NULL, NULL, NULL) >= 0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
118 return CONTROL_TRUE; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
119 else |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
120 return CONTROL_FALSE; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
121 case ADCTRL_SKIP_FRAME: |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
122 start = mpa_sync(sh, 2, &len, NULL, NULL, NULL, NULL, NULL); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
123 if(len < 0) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
124 return CONTROL_FALSE; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
125 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
126 sh->a_in_buffer_len -= start; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
127 memmove(sh->a_in_buffer, &(sh->a_in_buffer[start]), sh->a_in_buffer_len); |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
128 return CONTROL_TRUE; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
129 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
130 return CONTROL_UNKNOWN; |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
131 } |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
132 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
133 |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
134 static void uninit(sh_audio_t *sh) |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
135 { |
2e20dd653147
ad_hwmpa: pass-through fake audio codec for hardware mpeg decoders
nicodvb
parents:
diff
changeset
|
136 } |