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 // there are some globals:
|
|
20 // ao_samplerate
|
|
21 // ao_channels
|
|
22 // ao_format
|
|
23 // ao_bps
|
|
24 // ao_outburst
|
|
25 // ao_buffersize
|
|
26
|
|
27 // to set/get/query special features/parameters
|
|
28 static int control(int cmd,int arg){
|
|
29 return -1;
|
|
30 }
|
|
31
|
|
32 // open & setup audio device
|
|
33 // return: 1=success 0=fail
|
|
34 static int init(int rate,int channels,int format,int flags){
|
|
35
|
|
36 ao_outburst=2000;
|
|
37 ao_format=format;
|
|
38
|
|
39 return 1;
|
|
40 }
|
|
41
|
|
42 // close audio device
|
|
43 static void uninit(){
|
|
44
|
|
45 }
|
|
46
|
|
47 // stop playing and empty buffers (for seeking/pause)
|
|
48 static void reset(){
|
|
49
|
|
50 }
|
|
51
|
|
52 // stop playing, keep buffers (for pause)
|
|
53 static void audio_pause()
|
|
54 {
|
|
55 // for now, just call reset();
|
|
56 reset();
|
|
57 }
|
|
58
|
|
59 // resume playing, after audio_pause()
|
|
60 static void audio_resume()
|
|
61 {
|
|
62 }
|
|
63
|
|
64 void send_pes_packet(unsigned char* data,int len,int id,int timestamp);
|
|
65 void send_lpcm_packet(unsigned char* data,int len,int id,int timestamp);
|
|
66 extern int vo_pts;
|
|
67
|
|
68 // return: how many bytes can be played without blocking
|
|
69 static int get_space(){
|
|
70 float x=(float)(vo_pts-ao_pts)/90000.0-0.5;
|
|
71 int y;
|
|
72 if(x<=0) return 0;
|
|
73 y=48000*4*x;y/=ao_outburst;y*=ao_outburst;
|
|
74 // printf("diff: %5.3f -> %d \n",x,y);
|
|
75 return y;
|
|
76 }
|
|
77
|
|
78 // plays 'len' bytes of 'data'
|
|
79 // it should round it down to outburst*n
|
|
80 // return: number of bytes played
|
|
81 static int play(void* data,int len,int flags){
|
|
82 if(ao_format==AFMT_MPEG)
|
|
83 send_pes_packet(data,len,0x1C0,ao_pts);
|
|
84 else {
|
|
85 int i;
|
|
86 unsigned short *s=data;
|
|
87 for(i=0;i<len/2;i++) s[i]=(s[i]>>8)|(s[i]<<8); // le<->be
|
|
88 send_lpcm_packet(data,len,0xA0,ao_pts);
|
|
89 }
|
|
90 return len;
|
|
91 }
|
|
92
|
|
93 // return: how many unplayed bytes are in the buffer
|
|
94 static int get_delay(){
|
|
95
|
|
96 return 0;
|
|
97 }
|
|
98
|