Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Paste
P670
virtual_oss new ffmpeg api
Active
Public
Actions
Authored by
christos
on Mon, Sep 8, 3:55 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F128187802: virtual_oss new ffmpeg api
Mon, Sep 8, 3:55 PM
2025-09-08 15:55:49 (UTC+0)
Subscribers
None
diff --git a/lib/virtual_oss/bt/Makefile b/lib/virtual_oss/bt/Makefile
index 3918a803c03a..3b0ed0eee29f 100644
--- a/lib/virtual_oss/bt/Makefile
+++ b/lib/virtual_oss/bt/Makefile
@@ -10,9 +10,10 @@ CFLAGS+= -I${SRCTOP}/usr.sbin/virtual_oss/virtual_oss \
LDFLAGS+= -lbluetooth -lsdp
LIBADD= samplerate
-.if defined(HAVE_FFMPEG)
-CFLAGS+= -DHAVE_FFMPEG
-LDFLAGS+= -lavdevice -lavutil -lavcodec -lavresample -lavformat
+.if defined(HAVE_LIBAV)
+CFLAGS+= -DHAVE_LIBAV -I/usr/local/include
+LDFLAGS+= -lavdevice -lavutil -lavcodec -lavformat -L/usr/local/lib
+ #-lavresample
.endif
.include <bsd.lib.mk>
diff --git a/lib/virtual_oss/bt/avdtp.c b/lib/virtual_oss/bt/avdtp.c
index 441c605c6673..82ed0fb942b6 100644
--- a/lib/virtual_oss/bt/avdtp.c
+++ b/lib/virtual_oss/bt/avdtp.c
@@ -385,7 +385,7 @@ avdtpAutoConfig(struct bt_config *cfg)
uint8_t supBitpoolMax = 0;
uint8_t aacMode1 = 0;
uint8_t aacMode2 = 0;
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
uint8_t aacBitrate3 = 0;
uint8_t aacBitrate4 = 0;
uint8_t aacBitrate5 = 0;
@@ -431,7 +431,7 @@ avdtpAutoConfig(struct bt_config *cfg)
break;
aacMode1 = info.buffer_data[i + 5];
aacMode2 = info.buffer_data[i + 6];
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
aacBitrate3 = info.buffer_data[i + 7];
aacBitrate4 = info.buffer_data[i + 8];
aacBitrate5 = info.buffer_data[i + 9];
@@ -449,7 +449,7 @@ avdtpAutoConfig(struct bt_config *cfg)
/* Try AAC first */
if (aacMode1 == cfg->aacMode1 && aacMode2 == cfg->aacMode2) {
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
uint8_t config[12] = { mediaTransport, 0x0, mediaCodec,
0x8, 0x0, 0x02, 0x80, aacMode1, aacMode2, aacBitrate3,
aacBitrate4, aacBitrate5
diff --git a/lib/virtual_oss/bt/bt.c b/lib/virtual_oss/bt/bt.c
index 5e63b6e18dd6..57f000b067d5 100644
--- a/lib/virtual_oss/bt/bt.c
+++ b/lib/virtual_oss/bt/bt.c
@@ -187,7 +187,7 @@ bt_play_close(struct voss_backend *pbe)
free(cfg->handle.sbc_enc);
cfg->handle.sbc_enc = NULL;
break;
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
case CODEC_AAC:
if (cfg->handle.av.context == NULL)
break;
@@ -212,7 +212,7 @@ bt_rec_close(struct voss_backend *pbe)
switch (cfg->codec) {
case CODEC_SBC:
break;
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
case CODEC_AAC:
break;
#endif
@@ -651,11 +651,10 @@ bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
return (-1);
memset(cfg->handle.sbc_enc, 0, sizeof(*cfg->handle.sbc_enc));
break;
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
case CODEC_AAC:
- av_register_all();
-
- cfg->handle.av.codec = avcodec_find_encoder_by_name("aac");
+ cfg->handle.av.codec = __DECONST(AVCodec *,
+ avcodec_find_encoder_by_name("aac"));
if (cfg->handle.av.codec == NULL) {
DPRINTF("Codec AAC encoder not found\n");
goto av_error_0;
@@ -678,25 +677,23 @@ bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
DPRINTF("Could not create new stream\n");
goto av_error_1;
}
- cfg->handle.av.context = cfg->handle.av.stream->codec;
+ cfg->handle.av.context = avcodec_alloc_context3(cfg->handle.av.codec);
if (cfg->handle.av.context == NULL) {
DPRINTF("Could not allocate audio context\n");
goto av_error_1;
}
- avcodec_get_context_defaults3(cfg->handle.av.context,
- cfg->handle.av.codec);
+ /*avcodec_get_context_defaults3(cfg->handle.av.context,*/
+ /*cfg->handle.av.codec);*/
cfg->handle.av.context->bit_rate = 128000;
cfg->handle.av.context->sample_fmt = AV_SAMPLE_FMT_FLTP;
cfg->handle.av.context->sample_rate = samplerate;
switch (*pchannels) {
case 1:
- cfg->handle.av.context->channel_layout = AV_CH_LAYOUT_MONO;
- cfg->handle.av.context->channels = 1;
+ cfg->handle.av.context->ch_layout = *(AVChannelLayout *)AV_CH_LAYOUT_MONO;
break;
default:
- cfg->handle.av.context->channel_layout = AV_CH_LAYOUT_STEREO;
- cfg->handle.av.context->channels = 2;
+ cfg->handle.av.context->ch_layout = *(AVChannelLayout *)AV_CH_LAYOUT_STEREO;
break;
}
@@ -723,9 +720,9 @@ bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
}
cfg->handle.av.frame->nb_samples = cfg->handle.av.context->frame_size;
cfg->handle.av.frame->format = cfg->handle.av.context->sample_fmt;
- cfg->handle.av.frame->channel_layout = cfg->handle.av.context->channel_layout;
+ cfg->handle.av.frame->ch_layout = cfg->handle.av.context->ch_layout;
cfg->rem_in_size = av_samples_get_buffer_size(NULL,
- cfg->handle.av.context->channels,
+ cfg->handle.av.context->ch_layout.nb_channels,
cfg->handle.av.context->frame_size,
cfg->handle.av.context->sample_fmt, 0);
@@ -736,7 +733,7 @@ bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
goto av_error_3;
}
retval = avcodec_fill_audio_frame(cfg->handle.av.frame,
- cfg->handle.av.context->channels,
+ cfg->handle.av.context->ch_layout.nb_channels,
cfg->handle.av.context->sample_fmt,
cfg->rem_in_data, cfg->rem_in_size, 0);
if (retval < 0) {
@@ -895,7 +892,7 @@ bt_play_sbc_transfer(struct voss_backend *pbe, void *ptr, int len)
return (err);
}
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
static int
bt_play_aac_transfer(struct voss_backend *pbe, void *ptr, int len)
{
@@ -921,7 +918,6 @@ bt_play_aac_transfer(struct voss_backend *pbe, void *ptr, int len)
while (len > 0) {
int delta = len;
int rem;
- int i;
if (delta > (int)(cfg->rem_in_size - cfg->rem_in_len))
delta = (int)(cfg->rem_in_size - cfg->rem_in_len);
@@ -935,26 +931,17 @@ bt_play_aac_transfer(struct voss_backend *pbe, void *ptr, int len)
/* check if buffer is full */
if (cfg->rem_in_len == cfg->rem_in_size) {
struct aac_header *phdr = (struct aac_header *)cfg->mtu_data;
- AVPacket pkt;
+ AVPacket *pkt;
uint8_t *pkt_buf;
int pkt_len;
- int got_output;
- int i;
-
- av_init_packet(&pkt);
- pkt.data = NULL;
- pkt.size = 0;
- err = avcodec_encode_audio2(cfg->handle.av.context,
- &pkt, cfg->handle.av.frame, &got_output);
+
+ pkt = av_packet_alloc();
+ err = avcodec_send_frame(cfg->handle.av.context,
+ cfg->handle.av.frame);
if (err < 0) {
DPRINTF("Error encoding audio frame\n");
return (-1);
}
- if (got_output == 0) {
- /* reset remaining length */
- cfg->rem_in_len = 0;
- continue;
- }
phdr->id = 0x80;/* RTP v2 */
phdr->id2 = 0x60; /* payload type 96. */
phdr->seqnumMSB = (uint8_t)(cfg->mtu_seqnumber >> 8);
@@ -986,9 +973,9 @@ bt_play_aac_transfer(struct voss_backend *pbe, void *ptr, int len)
static int once = 0;
if (!once++)
- avformat_write_header(cfg->handle.av.format, NULL);
- av_write_frame(cfg->handle.av.format, &pkt);
- av_free_packet(&pkt);
+ (void)avformat_write_header(cfg->handle.av.format, NULL);
+ av_write_frame(cfg->handle.av.format, pkt);
+ av_packet_unref(pkt);
pkt_len = avio_close_dyn_buf(cfg->handle.av.format->pb, &pkt_buf);
if (rem < pkt_len)
DPRINTF("Out of buffer space\n");
@@ -1014,7 +1001,7 @@ bt_play_aac_transfer(struct voss_backend *pbe, void *ptr, int len)
av_free(pkt_buf);
}
} else {
- av_free_packet(&pkt);
+ av_packet_unref(pkt);
}
/* reset remaining length */
cfg->rem_in_len = 0;
@@ -1035,7 +1022,7 @@ bt_play_transfer(struct voss_backend *pbe, void *ptr, int len)
switch (cfg->codec) {
case CODEC_SBC:
return (bt_play_sbc_transfer(pbe, ptr, len));
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
case CODEC_AAC:
return (bt_play_aac_transfer(pbe, ptr, len));
#endif
diff --git a/lib/virtual_oss/bt/bt.h b/lib/virtual_oss/bt/bt.h
index 3c848f7e0d66..2abdb9eb021a 100644
--- a/lib/virtual_oss/bt/bt.h
+++ b/lib/virtual_oss/bt/bt.h
@@ -26,7 +26,7 @@
#ifndef _BACKEND_BT_H_
#define _BACKEND_BT_H_
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
@@ -69,7 +69,7 @@ struct bt_config {
/* transcoding handle(s) */
union {
-#ifdef HAVE_FFMPEG
+#ifdef HAVE_LIBAV
struct {
AVCodec *codec;
AVCodecContext *context;
Event Timeline
christos
created this paste.
Mon, Sep 8, 3:55 PM
2025-09-08 15:55:49 (UTC+0)
christos
created this object in space
S1 Global
.
christos
mentioned this in
D52308: virtual_oss: Port to base
.
Mon, Sep 8, 3:56 PM
2025-09-08 15:56:24 (UTC+0)
Log In to Comment