annotate beosaudio.cpp @ 479:d84d9d8bb0a4 libavformat

pass timestamps correctly for -sync 0 use zero sized frames in avi to handle duplicate frames
author michael
date Tue, 15 Jun 2004 13:49:12 +0000
parents 8c55237af288
children c33bf4d10c4c
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>
153
41d4f3a86c98 cleanup; BSoundRecorder moved to Experimental namespace
mmu_man
parents: 108
diff changeset
36 using namespace BPrivate::Media::Experimental;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
37 #endif
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
38
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 /* enable performance checks */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 //#define PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
108
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
42 /* enable Media Kit latency checks */
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
43 //#define LATENCY_CHECK
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
44
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 #define AUDIO_BLOCK_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 #define AUDIO_BLOCK_COUNT 8
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 #define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 typedef struct {
95
89e992063014 cleanup; unused pipe() stuff removed.
mmu_man
parents: 66
diff changeset
51 int fd; // UNUSED
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 int sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 int channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 int frame_size; /* in bytes ! */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 CodecID codec_id;
66
ad9bcf041e8e Looks like this one was forgotten in the INT -> int_t move
mmu_man
parents: 30
diff changeset
56 uint8_t buffer[AUDIO_BUFFER_SIZE];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 int buffer_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 /* ring buffer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 sem_id input_sem;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 int input_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 sem_id output_sem;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 int output_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 BSoundPlayer *player;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
64 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
65 BSoundRecorder *recorder;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
66 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 int has_quit; /* signal callbacks not to wait */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 volatile bigtime_t starve_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 } AudioData;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 static thread_id main_thid;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 static thread_id bapp_thid;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 static int own_BApp_created = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 static int refcount = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 /* create the BApplication and Run() it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 static int32 bapp_thread(void *arg)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 new BApplication("application/x-vnd.ffmpeg");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 own_BApp_created = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 be_app->Run();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 /* kill the process group */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 // kill(0, SIGINT);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 // kill(main_thid, SIGHUP);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 return B_OK;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 /* create the BApplication only if needed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 static void create_bapp_if_needed(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 if (refcount++ == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 /* needed by libmedia */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 if (be_app == NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 resume_thread(bapp_thid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 while (!own_BApp_created)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 snooze(50000);
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 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 static void destroy_bapp_if_needed(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 if (--refcount == 0 && own_BApp_created) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 be_app->Lock();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 be_app->Quit();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 be_app = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 /* called back by BSoundPlayer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 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
113 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 AudioData *s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 size_t len, amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 unsigned char *buf = (unsigned char *)buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 s = (AudioData *)cookie;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 if (s->has_quit)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 while (bufferSize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 #ifdef PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 bigtime_t t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 t = system_time();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 len = MIN(AUDIO_BLOCK_SIZE, bufferSize);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 s->has_quit = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 s->player->SetHasData(false);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 return;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 memcpy(buf, &s->buffer[s->output_index], amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 s->output_index += amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 if (s->output_index >= AUDIO_BUFFER_SIZE) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 s->output_index %= AUDIO_BUFFER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 s->output_index += len-amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 s->output_index %= AUDIO_BUFFER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 release_sem_etc(s->input_sem, len, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 #ifdef PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 t = system_time() - t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 s->starve_time = MAX(s->starve_time, t);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 bufferSize -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
151 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
152 /* called back by BSoundRecorder */
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
153 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
154 {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
155 AudioData *s;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
156 size_t len, amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
157 unsigned char *buf = (unsigned char *)buffer;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
158
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
159 s = (AudioData *)cookie;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
160 if (s->has_quit)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
161 return;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
162
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
163 while (bufferSize > 0) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
164 len = MIN(bufferSize, AUDIO_BLOCK_SIZE);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
165 //printf("acquire_sem(input, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
166 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
167 s->has_quit = 1;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
168 return;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
169 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
170 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
171 memcpy(&s->buffer[s->input_index], buf, amount);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
172 s->input_index += amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
173 if (s->input_index >= AUDIO_BUFFER_SIZE) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
174 s->input_index %= AUDIO_BUFFER_SIZE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
175 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
176 s->input_index += len - amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
177 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
178 release_sem_etc(s->output_sem, len, 0);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
179 //printf("release_sem(output, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
180 buf += len;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
181 bufferSize -= len;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
182 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
183 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
184 #endif
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
185
97
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
186 static int audio_open(AudioData *s, int is_output, const char *audio_device)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 int p[2];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 media_raw_audio_format format;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
191 media_multi_audio_format iformat;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
193 #ifndef HAVE_BSOUNDRECORDER
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 if (!is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 return -EIO; /* not for now */
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
196 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 if (s->input_sem < B_OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 if (s->output_sem < B_OK) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 delete_sem(s->input_sem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 s->input_index = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 s->output_index = 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) {
97
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
213 bool wait_for_input = false;
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
214 if (audio_device && !strcmp(audio_device, "wait:"))
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
215 wait_for_input = true;
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
216 s->recorder = new BSoundRecorder(&iformat, wait_for_input, "ffmpeg input", audiorecord_callback);
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
217 if (wait_for_input && (s->recorder->InitCheck() == B_OK)) {
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
218 s->recorder->WaitForIncomingConnection(&iformat);
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
219 }
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
220 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
221 delete s->recorder;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
222 s->recorder = NULL;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
223 if (s->input_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
224 delete_sem(s->input_sem);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
225 if (s->output_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
226 delete_sem(s->output_sem);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
227 return -EIO;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
228 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
229 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
230 s->channels = iformat.channel_count;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
231 s->sample_rate = (int)iformat.frame_rate;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
232 s->frame_size = iformat.buffer_size;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
233 s->recorder->SetCookie(s);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
234 s->recorder->SetVolume(1.0);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
235 s->recorder->Start();
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
236 return 0;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
237 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
238 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 format = media_raw_audio_format::wildcard;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 format.format = media_raw_audio_format::B_AUDIO_SHORT;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 format.channel_count = s->channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 format.buffer_size = s->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 format.frame_rate = s->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 if (s->player->InitCheck() != B_OK) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 delete s->player;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 s->player = NULL;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
249 if (s->input_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
250 delete_sem(s->input_sem);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
251 if (s->output_sem)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
252 delete_sem(s->output_sem);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 s->player->SetCookie(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 s->player->SetVolume(1.0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 s->player->Start();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 s->player->SetHasData(true);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 static int audio_close(AudioData *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 if (s->input_sem)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 delete_sem(s->input_sem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 if (s->output_sem)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 delete_sem(s->output_sem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 s->has_quit = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 if (s->player) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 s->player->Stop();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 if (s->player)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 delete s->player;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
274 #ifdef HAVE_BSOUNDRECORDER
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
275 if (s->recorder)
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
276 delete s->recorder;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
277 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 destroy_bapp_if_needed();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 /* sound output support */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 static int audio_write_header(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 s->sample_rate = st->codec.sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 s->channels = st->codec.channels;
97
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
292 ret = audio_open(s, 1, NULL);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 static int audio_write_packet(AVFormatContext *s1, int stream_index,
246
8c55237af288 64 bit pts for writing - more const usage (don't forget me !)
mmu_man
parents: 153
diff changeset
299 const uint8_t *buf, int size, int64_t force_pts)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 int len, ret;
108
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
303 #ifdef LATENCY_CHECK
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
304 bigtime_t lat1, lat2;
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
305 lat1 = s->player->Latency();
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
306 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 #ifdef PERF_CHECK
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 bigtime_t t = s->starve_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 s->starve_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 printf("starve_time: %lld \n", t);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 int amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 len = MIN(size, AUDIO_BLOCK_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 memcpy(&s->buffer[s->input_index], buf, amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 s->input_index += amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 if (s->input_index >= AUDIO_BUFFER_SIZE) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 s->input_index %= AUDIO_BUFFER_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 s->input_index += len - amount;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 release_sem_etc(s->output_sem, len, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 }
108
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
329 #ifdef LATENCY_CHECK
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
330 lat2 = s->player->Latency();
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
331 printf("#### BSoundPlayer::Latency(): before= %lld, after= %lld\n", lat1, lat2);
c1c8a0777bdb Add latency check, the Media Kit shoul repport it, but this seems broken.
mmu_man
parents: 97
diff changeset
332 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 static int audio_write_trailer(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 audio_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 /* grab support */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 st = av_new_stream(s1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 if (!st) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 s->sample_rate = ap->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 s->channels = ap->channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
97
265d01c2248f the media node now won't connect itself to the default audio input with -ad wait:
mmu_man
parents: 96
diff changeset
362 ret = audio_open(s, 0, ap->device);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 av_free(st);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 }
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
367 /* take real parameters */
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
368 st->codec.codec_type = CODEC_TYPE_AUDIO;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
369 st->codec.codec_id = s->codec_id;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
370 st->codec.sample_rate = s->sample_rate;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
371 st->codec.channels = s->channels;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
372 return 0;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
373 av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 AudioData *s = (AudioData *)s1->priv_data;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
379 int size;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
380 size_t len, amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
381 unsigned char *buf;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
382 status_t err;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 if (av_new_packet(pkt, s->frame_size) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 return -EIO;
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
386 buf = (unsigned char *)pkt->data;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
387 size = pkt->size;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
388 while (size > 0) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
389 len = MIN(AUDIO_BLOCK_SIZE, size);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
390 //printf("acquire_sem(output, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
391 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
392 if (err < B_OK) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 av_free_packet(pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 return -EIO;
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 amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
397 memcpy(buf, &s->buffer[s->output_index], amount);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
398 s->output_index += amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
399 if (s->output_index >= AUDIO_BUFFER_SIZE) {
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
400 s->output_index %= AUDIO_BUFFER_SIZE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
401 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
402 s->output_index += len-amount;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
403 s->output_index %= AUDIO_BUFFER_SIZE;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
404 }
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
405 release_sem_etc(s->input_sem, len, 0);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
406 //printf("release_sem(input, %d)\n", len);
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
407 buf += len;
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
408 size -= len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 }
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
410 //XXX: add pts info
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 static int audio_read_close(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 AudioData *s = (AudioData *)s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 audio_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421
96
2d3083edb99f experimental BeOS audio input support. (needs unreleased library)
mmu_man
parents: 95
diff changeset
422 static AVInputFormat audio_in_format = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 "audio_device",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 "audio grab and output",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 sizeof(AudioData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 audio_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 audio_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 audio_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 AVFMT_NOFILE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 AVOutputFormat audio_out_format = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 "audio_device",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 "audio grab and output",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 "",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 sizeof(AudioData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 #ifdef WORDS_BIGENDIAN
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 CODEC_ID_PCM_S16BE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 CODEC_ID_PCM_S16LE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 CODEC_ID_NONE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 audio_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 audio_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 audio_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 AVFMT_NOFILE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 extern "C" {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 int audio_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 main_thid = find_thread(NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 av_register_input_format(&audio_in_format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 av_register_output_format(&audio_out_format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 } // "C"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463