annotate beosaudio.cpp @ 96:2d3083edb99f libavformat

experimental BeOS audio input support. (needs unreleased library)
author mmu_man
date Thu, 27 Mar 2003 14:44:30 +0000
parents 89e992063014
children 265d01c2248f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * BeOS audio play interface
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include <signal.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include <stdlib.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <stdio.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <string.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #include <sys/time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #include <Application.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #include <SoundPlayer.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 extern "C" {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
34 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
35 #include <SoundRecorder.h>
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
36 #endif
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
37
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 /* enable performance checks */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 //#define PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 #define AUDIO_BLOCK_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 //#define AUDIO_BLOCK_SIZE 2048
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 #define AUDIO_BLOCK_COUNT 8
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 #define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 typedef struct {
95
89e992063014 cleanup; unused pipe() stuff removed.
mmu_man
parents: 66
diff changeset
48 int fd; // UNUSED
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 int sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 int channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 int frame_size; /* in bytes ! */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 CodecID codec_id;
66
ad9bcf041e8e Looks like this one was forgotten in the INT -> int_t move
mmu_man
parents: 30
diff changeset
53 uint8_t buffer[AUDIO_BUFFER_SIZE];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 int buffer_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 /* ring buffer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 sem_id input_sem;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 int input_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 sem_id output_sem;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 int output_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 int queued;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 BSoundPlayer *player;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
62 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
63 BSoundRecorder *recorder;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
64 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 int has_quit; /* signal callbacks not to wait */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 volatile bigtime_t starve_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 } AudioData;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 static thread_id main_thid;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 static thread_id bapp_thid;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 static int own_BApp_created = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 static int refcount = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 /* create the BApplication and Run() it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 static int32 bapp_thread(void *arg)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 new BApplication("application/x-vnd.ffmpeg");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 own_BApp_created = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 be_app->Run();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 /* kill the process group */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 // kill(0, SIGINT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 // kill(main_thid, SIGHUP);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 return B_OK;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 /* create the BApplication only if needed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 static void create_bapp_if_needed(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 if (refcount++ == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 /* needed by libmedia */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 if (be_app == NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 resume_thread(bapp_thid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 while (!own_BApp_created)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 snooze(50000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 static void destroy_bapp_if_needed(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 if (--refcount == 0 && own_BApp_created) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 be_app->Lock();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 be_app->Quit();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 be_app = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 /* called back by BSoundPlayer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 AudioData *s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 size_t len, amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 unsigned char *buf = (unsigned char *)buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 s = (AudioData *)cookie;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 if (s->has_quit)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 while (bufferSize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 #ifdef PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 bigtime_t t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 t = system_time();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 len = MIN(AUDIO_BLOCK_SIZE, bufferSize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 s->has_quit = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 s->player->SetHasData(false);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 memcpy(buf, &s->buffer[s->output_index], amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 s->output_index += amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 if (s->output_index >= AUDIO_BUFFER_SIZE) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 s->output_index %= AUDIO_BUFFER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 s->output_index += len-amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 s->output_index %= AUDIO_BUFFER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 release_sem_etc(s->input_sem, len, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 #ifdef PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 t = system_time() - t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 s->starve_time = MAX(s->starve_time, t);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 bufferSize -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
149 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
150 /* called back by BSoundRecorder */
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
151 static void audiorecord_callback(void *cookie, bigtime_t timestamp, void *buffer, size_t bufferSize, const media_multi_audio_format &format)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
152 {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
153 AudioData *s;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
154 size_t len, amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
155 unsigned char *buf = (unsigned char *)buffer;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
156
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
157 s = (AudioData *)cookie;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
158 if (s->has_quit)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
159 return;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
160
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
161 while (bufferSize > 0) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
162 len = MIN(bufferSize, AUDIO_BLOCK_SIZE);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
163 //printf("acquire_sem(input, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
164 if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
165 s->has_quit = 1;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
166 return;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
167 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
168 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
169 memcpy(&s->buffer[s->input_index], buf, amount);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
170 s->input_index += amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
171 if (s->input_index >= AUDIO_BUFFER_SIZE) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
172 s->input_index %= AUDIO_BUFFER_SIZE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
173 memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
174 s->input_index += len - amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
175 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
176 release_sem_etc(s->output_sem, len, 0);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
177 //printf("release_sem(output, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
178 buf += len;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
179 bufferSize -= len;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
180 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
181 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
182 #endif
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
183
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 static int audio_open(AudioData *s, int is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 int p[2];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 media_raw_audio_format format;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
189 media_multi_audio_format iformat;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
191 #ifndef HAVE_BSOUNDRECORDER
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 if (!is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 return -EIO; /* not for now */
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
194 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 // s->input_sem = create_sem(AUDIO_BLOCK_SIZE, "ffmpeg_ringbuffer_input");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 if (s->input_sem < B_OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 if (s->output_sem < B_OK) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 delete_sem(s->input_sem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 s->input_index = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 s->output_index = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 s->queued = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 create_bapp_if_needed();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 s->frame_size = AUDIO_BLOCK_SIZE;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
209 /* bump up the priority (avoid realtime though) */
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
210 set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
211 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
212 if (!is_output) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
213 s->recorder = new BSoundRecorder(&iformat, false, "ffmpeg input", audiorecord_callback);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
214 if (s->recorder->InitCheck() != B_OK || iformat.format != media_raw_audio_format::B_AUDIO_SHORT) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
215 delete s->recorder;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
216 s->recorder = NULL;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
217 if (s->input_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
218 delete_sem(s->input_sem);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
219 if (s->output_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
220 delete_sem(s->output_sem);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
221 return -EIO;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
222 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
223 s->codec_id = (iformat.byte_order == B_MEDIA_LITTLE_ENDIAN)?CODEC_ID_PCM_S16LE:CODEC_ID_PCM_S16BE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
224 s->channels = iformat.channel_count;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
225 s->sample_rate = (int)iformat.frame_rate;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
226 s->frame_size = iformat.buffer_size;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
227 s->recorder->SetCookie(s);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
228 s->recorder->SetVolume(1.0);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
229 s->recorder->Start();
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
230 return 0;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
231 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
232 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 format = media_raw_audio_format::wildcard;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 format.format = media_raw_audio_format::B_AUDIO_SHORT;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 format.channel_count = s->channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 format.buffer_size = s->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 format.frame_rate = s->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 if (s->player->InitCheck() != B_OK) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 delete s->player;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 s->player = NULL;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
243 if (s->input_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
244 delete_sem(s->input_sem);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
245 if (s->output_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
246 delete_sem(s->output_sem);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 s->player->SetCookie(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 s->player->SetVolume(1.0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 s->player->Start();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 s->player->SetHasData(true);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 static int audio_close(AudioData *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 if (s->input_sem)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 delete_sem(s->input_sem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 if (s->output_sem)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 delete_sem(s->output_sem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 s->has_quit = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 if (s->player) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 s->player->Stop();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 if (s->player)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 delete s->player;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
268 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
269 if (s->recorder)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
270 delete s->recorder;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
271 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 destroy_bapp_if_needed();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 /* sound output support */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 static int audio_write_header(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 s->sample_rate = st->codec.sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 s->channels = st->codec.channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 ret = audio_open(s, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 static int audio_write_packet(AVFormatContext *s1, int stream_index,
66
ad9bcf041e8e Looks like this one was forgotten in the INT -> int_t move
mmu_man
parents: 30
diff changeset
293 uint8_t *buf, int size, int force_pts)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 int len, ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 #ifdef PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 bigtime_t t = s->starve_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 s->starve_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 printf("starve_time: %lld \n", t);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 int amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 len = MIN(size, AUDIO_BLOCK_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 memcpy(&s->buffer[s->input_index], buf, amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 s->input_index += amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 if (s->input_index >= AUDIO_BUFFER_SIZE) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 s->input_index %= AUDIO_BUFFER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 s->input_index += len - amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 release_sem_etc(s->output_sem, len, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 static int audio_write_trailer(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 audio_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 /* grab support */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 st = av_new_stream(s1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 if (!st) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 s->sample_rate = ap->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 s->channels = ap->channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 ret = audio_open(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 av_free(st);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 }
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
353 /* take real parameters */
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
354 st->codec.codec_type = CODEC_TYPE_AUDIO;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
355 st->codec.codec_id = s->codec_id;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
356 st->codec.sample_rate = s->sample_rate;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
357 st->codec.channels = s->channels;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
358 return 0;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
359 av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 AudioData *s = (AudioData *)s1->priv_data;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
365 int size;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
366 size_t len, amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
367 unsigned char *buf;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
368 status_t err;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 if (av_new_packet(pkt, s->frame_size) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 return -EIO;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
372 buf = (unsigned char *)pkt->data;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
373 size = pkt->size;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
374 while (size > 0) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
375 len = MIN(AUDIO_BLOCK_SIZE, size);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
376 //printf("acquire_sem(output, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
377 while ((err=acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL)) == B_INTERRUPTED);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
378 if (err < B_OK) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 av_free_packet(pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 }
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
382 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
383 memcpy(buf, &s->buffer[s->output_index], amount);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
384 s->output_index += amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
385 if (s->output_index >= AUDIO_BUFFER_SIZE) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
386 s->output_index %= AUDIO_BUFFER_SIZE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
387 memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
388 s->output_index += len-amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
389 s->output_index %= AUDIO_BUFFER_SIZE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
390 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
391 release_sem_etc(s->input_sem, len, 0);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
392 //printf("release_sem(input, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
393 buf += len;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
394 size -= len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 }
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
396 //XXX: add pts info
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 static int audio_read_close(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 audio_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
408 static AVInputFormat audio_in_format = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 "audio_device",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 "audio grab and output",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 sizeof(AudioData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 audio_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 audio_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 audio_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 AVFMT_NOFILE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 AVOutputFormat audio_out_format = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 "audio_device",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 "audio grab and output",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 sizeof(AudioData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 #ifdef WORDS_BIGENDIAN
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 CODEC_ID_PCM_S16BE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 CODEC_ID_PCM_S16LE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 CODEC_ID_NONE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 audio_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 audio_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 audio_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 AVFMT_NOFILE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 extern "C" {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 int audio_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 main_thid = find_thread(NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 av_register_input_format(&audio_in_format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 av_register_output_format(&audio_out_format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 } // "C"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449