annotate libao2/ao_mpegpes.c @ 4275:818be6ba8758

initial implementation of SMC codec; it almost works, too!
author melanson
date Sun, 20 Jan 2002 01:35:02 +0000
parents 981a9e5118ce
children 4ebab79785b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
1 #include <stdio.h>
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
2 #include <stdlib.h>
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
3
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
4 #include "audio_out.h"
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
5 #include "audio_out_internal.h"
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
6
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
7 #include "afmt.h"
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
8
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
9 static ao_info_t info =
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
10 {
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
11 "mpeg-pes audio output",
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
12 "mpegpes",
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
13 "A'rpi",
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
14 ""
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
15 };
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
16
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
17 LIBAO_EXTERN(mpegpes)
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
18
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
19
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
20 // to set/get/query special features/parameters
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
21 static int control(int cmd,int arg){
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
22 return -1;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
23 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
24
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
25 // open & setup audio device
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
26 // return: 1=success 0=fail
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
27 static int init(int rate,int channels,int format,int flags){
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
28
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
29 ao_data.outburst=2000;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
30 ao_data.format=format;
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
31
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
32 return 1;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
33 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
34
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
35 // close audio device
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
36 static void uninit(){
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
37
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
38 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
39
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
40 // stop playing and empty buffers (for seeking/pause)
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
41 static void reset(){
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
42
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
43 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
44
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
45 // stop playing, keep buffers (for pause)
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
46 static void audio_pause()
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
47 {
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
48 // for now, just call reset();
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
49 reset();
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
50 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
51
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
52 // resume playing, after audio_pause()
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
53 static void audio_resume()
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
54 {
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
55 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
56
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
57 void send_pes_packet(unsigned char* data,int len,int id,int timestamp);
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
58 void send_lpcm_packet(unsigned char* data,int len,int id,int timestamp);
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
59 extern int vo_pts;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
60
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
61 // return: how many bytes can be played without blocking
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
62 static int get_space(){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
63 float x=(float)(vo_pts-ao_data.pts)/90000.0-0.5;
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
64 int y;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
65 if(x<=0) return 0;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
66 y=48000*4*x;y/=ao_data.outburst;y*=ao_data.outburst;
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
67 // printf("diff: %5.3f -> %d \n",x,y);
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
68 return y;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
69 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
70
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
71 // plays 'len' bytes of 'data'
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
72 // it should round it down to outburst*n
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
73 // return: number of bytes played
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
74 static int play(void* data,int len,int flags){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
75 if(ao_data.format==AFMT_MPEG)
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
76 send_pes_packet(data,len,0x1C0,ao_data.pts);
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
77 else {
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
78 int i;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
79 unsigned short *s=data;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
80 for(i=0;i<len/2;i++) s[i]=(s[i]>>8)|(s[i]<<8); // le<->be
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
81 send_lpcm_packet(data,len,0xA0,ao_data.pts);
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
82 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
83 return len;
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
84 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
85
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
86 // return: delay in seconds between first and last sample in buffer
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
87 static float get_delay(){
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
88
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2708
diff changeset
89 return 0.0;
2708
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
90 }
b24661a9924e ao_mpegpes
arpi
parents:
diff changeset
91