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