annotate libao2/ao_mpegpes.c @ 3042:6b6fa2be9b97

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