annotate beosaudio.cpp @ 2582:1f9d02d072a7 libavformat

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