Skip to content

Commit

Permalink
Merge pull request #185 from ko80/fix-audio-buf-size-memif
Browse files Browse the repository at this point in the history
Fix audio buffer size + Rework of PCM16/24 support
  • Loading branch information
ko80 authored Sep 10, 2024
2 parents dde0aae + d118e06 commit 2b1a469
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 130 deletions.
41 changes: 22 additions & 19 deletions ffmpeg-plugin/6.1/0001-mcm-add-in-out-dev-support.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
From fbb0700ea7bd9b055ae9e43746a7751be88a8955 Mon Sep 17 00:00:00 2001
From 496a92977701bd5f665afe6b8171208457418585 Mon Sep 17 00:00:00 2001
From: Konstantin Ilichev <[email protected]>
Date: Wed, 21 Aug 2024 14:55:08 +0000
Date: Fri, 6 Sep 2024 18:33:01 +0000
Subject: [PATCH] Enable FFmpeg support in MCM

---
configure | 9 +++++++++
libavdevice/Makefile | 5 +++++
libavdevice/alldevices.c | 5 +++++
3 files changed, 19 insertions(+)
configure | 10 ++++++++++
libavdevice/Makefile | 6 ++++++
libavdevice/alldevices.c | 6 ++++++
3 files changed, 22 insertions(+)

diff --git a/configure b/configure
index 5af693c954..60caa4ebdf 100755
index ff11033a01..96c17b34c7 100755
--- a/configure
+++ b/configure
@@ -285,6 +285,7 @@ External library support:
Expand All @@ -29,19 +29,20 @@ index 5af693c954..60caa4ebdf 100755
libaom
libaribcaption
libass
@@ -3567,6 +3569,11 @@ xwma_demuxer_select="riffdec"
@@ -3568,6 +3570,12 @@ xwma_demuxer_select="riffdec"
android_camera_indev_deps="android camera2ndk mediandk pthreads"
alsa_indev_deps="alsa"
alsa_outdev_deps="alsa"
+mcm_indev_deps="libmcm_dp"
+mcm_outdev_deps="libmcm_dp"
+mcm_audio_indev_deps="libmcm_dp"
+mcm_audio_outdev_deps="libmcm_dp"
+mcm_audio_pcm16_indev_deps="libmcm_dp"
+mcm_audio_pcm24_indev_deps="libmcm_dp"
+mcm_audio_pcm16_outdev_deps="libmcm_dp"
+mcm_audio_pcm24_outdev_deps="libmcm_dp"
avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
avfoundation_indev_suggest="coregraphics applicationservices"
avfoundation_indev_extralibs="-framework Foundation"
@@ -6692,6 +6699,8 @@ enabled libaribb24 && { check_pkg_config libaribb24 "aribb24 > 1.0.3" "ar
@@ -6693,6 +6701,8 @@ enabled libaribb24 && { check_pkg_config libaribb24 "aribb24 > 1.0.3" "ar
enabled libaribcaption && require_pkg_config libaribcaption "libaribcaption >= 1.1.1" "aribcaption/aribcaption.h" aribcc_context_alloc
enabled lv2 && require_pkg_config lv2 lilv-0 "lilv/lilv.h" lilv_world_new
enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
Expand All @@ -51,34 +52,36 @@ index 5af693c954..60caa4ebdf 100755
enabled libbluray && require_pkg_config libbluray libbluray libbluray/bluray.h bd_open
enabled libbs2b && require_pkg_config libbs2b libbs2b bs2b.h bs2b_open
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index c30449201d..62bda757c3 100644
index c30449201d..1d7c0d1a10 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -20,6 +20,11 @@ OBJS-$(CONFIG_AUDIOTOOLBOX_OUTDEV) += audiotoolbox.o
@@ -20,6 +20,12 @@ OBJS-$(CONFIG_AUDIOTOOLBOX_OUTDEV) += audiotoolbox.o
OBJS-$(CONFIG_AVFOUNDATION_INDEV) += avfoundation.o
OBJS-$(CONFIG_BKTR_INDEV) += bktr.o
OBJS-$(CONFIG_CACA_OUTDEV) += caca.o
+OBJS-$(CONFIG_MCM_INDEV) += mcm_video_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_OUTDEV) += mcm_video_tx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_INDEV) += mcm_audio_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_OUTDEV) += mcm_audio_tx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM16_INDEV) += mcm_audio_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM24_INDEV) += mcm_audio_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM16_OUTDEV) += mcm_audio_tx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM24_OUTDEV) += mcm_audio_tx.o mcm_common.o
OBJS-$(CONFIG_DECKLINK_OUTDEV) += decklink_enc.o decklink_enc_c.o decklink_common.o
OBJS-$(CONFIG_DECKLINK_INDEV) += decklink_dec.o decklink_dec_c.o decklink_common.o
OBJS-$(CONFIG_DSHOW_INDEV) += dshow_crossbar.o dshow.o dshow_enummediatypes.o \
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 8a90fcb5d7..fe0eabdd67 100644
index 8a90fcb5d7..40c25ff009 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -25,6 +25,11 @@
@@ -25,6 +25,12 @@
/* devices */
extern const AVInputFormat ff_alsa_demuxer;
extern const FFOutputFormat ff_alsa_muxer;
+extern const AVInputFormat ff_mcm_demuxer;
+extern const FFOutputFormat ff_mcm_muxer;
+extern const AVInputFormat ff_mcm_audio_demuxer;
+extern const FFOutputFormat ff_mcm_audio_muxer;
+extern const AVInputFormat ff_mcm_audio_pcm16_demuxer;
+extern const AVInputFormat ff_mcm_audio_pcm24_demuxer;
+extern const FFOutputFormat ff_mcm_audio_pcm16_muxer;
+extern const FFOutputFormat ff_mcm_audio_pcm24_muxer;
extern const AVInputFormat ff_android_camera_demuxer;
extern const FFOutputFormat ff_audiotoolbox_muxer;
extern const AVInputFormat ff_avfoundation_demuxer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
From 0b5b445454655f3bbe326fef865a418a2de03f08 Mon Sep 17 00:00:00 2001
From: Tomasz Szumski <tomasz.szumski@intel.com>
Date: Thu, 29 Aug 2024 09:12:42 +0200
From 8e3a267c09b6f270ca1411f5c9f4e7fb0e1af8cb Mon Sep 17 00:00:00 2001
From: Konstantin Ilichev <konstantin.ilichev@intel.com>
Date: Fri, 6 Sep 2024 20:33:36 +0000
Subject: [PATCH] Enable FFmpeg support in MCM

---
configure | 9 +++++++++
libavdevice/Makefile | 5 +++++
libavdevice/alldevices.c | 5 +++++
3 files changed, 19 insertions(+)
configure | 10 ++++++++++
libavdevice/Makefile | 6 ++++++
libavdevice/alldevices.c | 6 ++++++
3 files changed, 22 insertions(+)

diff --git a/configure b/configure
index bde796d03a..f9eb340f7a 100755
index 20d4e4b615..9fdac37877 100755
--- a/configure
+++ b/configure
@@ -290,6 +290,7 @@ External library support:
Expand All @@ -21,27 +21,28 @@ index bde796d03a..f9eb340f7a 100755
--enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no]
--enable-libwebp enable WebP encoding via libwebp [no]
--enable-libx264 enable H.264 encoding via x264 [no]
@@ -1903,6 +1904,7 @@ EXTERNAL_LIBRARY_LIST="
@@ -1902,6 +1903,7 @@ EXTERNAL_LIBRARY_LIST="
jni
ladspa
lcms2
+ mcm
libaom
libaribcaption
libass
@@ -3665,6 +3667,11 @@ xwma_demuxer_select="riffdec"
@@ -3662,6 +3664,12 @@ xwma_demuxer_select="riffdec"
android_camera_indev_deps="android camera2ndk mediandk pthreads"
alsa_indev_deps="alsa"
alsa_outdev_deps="alsa"
+mcm_indev_deps="libmcm_dp"
+mcm_outdev_deps="libmcm_dp"
+mcm_audio_indev_deps="libmcm_dp"
+mcm_audio_outdev_deps="libmcm_dp"
+mcm_audio_pcm16_indev_deps="libmcm_dp"
+mcm_audio_pcm24_indev_deps="libmcm_dp"
+mcm_audio_pcm16_outdev_deps="libmcm_dp"
+mcm_audio_pcm24_outdev_deps="libmcm_dp"
avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
avfoundation_indev_suggest="coregraphics applicationservices"
avfoundation_indev_extralibs="-framework Foundation"
@@ -6834,6 +6841,8 @@ enabled libaribb24 && { check_pkg_config libaribb24 "aribb24 > 1.0.3" "ar
@@ -6831,6 +6839,8 @@ enabled libaribb24 && { check_pkg_config libaribb24 "aribb24 > 1.0.3" "ar
enabled libaribcaption && require_pkg_config libaribcaption "libaribcaption >= 1.1.1" "aribcaption/aribcaption.h" aribcc_context_alloc
enabled lv2 && require_pkg_config lv2 lilv-0 "lilv/lilv.h" lilv_world_new
enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
Expand All @@ -51,37 +52,39 @@ index bde796d03a..f9eb340f7a 100755
enabled libbluray && require_pkg_config libbluray libbluray libbluray/bluray.h bd_open
enabled libbs2b && require_pkg_config libbs2b libbs2b bs2b.h bs2b_open
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index c30449201d..62bda757c3 100644
index c30449201d..1d7c0d1a10 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -20,6 +20,11 @@ OBJS-$(CONFIG_AUDIOTOOLBOX_OUTDEV) += audiotoolbox.o
@@ -20,6 +20,12 @@ OBJS-$(CONFIG_AUDIOTOOLBOX_OUTDEV) += audiotoolbox.o
OBJS-$(CONFIG_AVFOUNDATION_INDEV) += avfoundation.o
OBJS-$(CONFIG_BKTR_INDEV) += bktr.o
OBJS-$(CONFIG_CACA_OUTDEV) += caca.o
+OBJS-$(CONFIG_MCM_INDEV) += mcm_video_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_OUTDEV) += mcm_video_tx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_INDEV) += mcm_audio_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_OUTDEV) += mcm_audio_tx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM16_INDEV) += mcm_audio_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM24_INDEV) += mcm_audio_rx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM16_OUTDEV) += mcm_audio_tx.o mcm_common.o
+OBJS-$(CONFIG_MCM_AUDIO_PCM24_OUTDEV) += mcm_audio_tx.o mcm_common.o
OBJS-$(CONFIG_DECKLINK_OUTDEV) += decklink_enc.o decklink_enc_c.o decklink_common.o
OBJS-$(CONFIG_DECKLINK_INDEV) += decklink_dec.o decklink_dec_c.o decklink_common.o
OBJS-$(CONFIG_DSHOW_INDEV) += dshow_crossbar.o dshow.o dshow_enummediatypes.o \
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 9b9a9146c7..a95f68850c 100644
index 9b9a9146c7..364c918cda 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -29,6 +29,11 @@ FF_VISIBILITY_PUSH_HIDDEN
@@ -29,6 +29,12 @@ FF_VISIBILITY_PUSH_HIDDEN
/* devices */
extern const FFInputFormat ff_alsa_demuxer;
extern const FFOutputFormat ff_alsa_muxer;
+extern const FFInputFormat ff_mcm_demuxer;
+extern const FFOutputFormat ff_mcm_muxer;
+extern const FFInputFormat ff_mcm_audio_demuxer;
+extern const FFOutputFormat ff_mcm_audio_muxer;
+extern const FFInputFormat ff_mcm_audio_pcm16_demuxer;
+extern const FFInputFormat ff_mcm_audio_pcm24_demuxer;
+extern const FFOutputFormat ff_mcm_audio_pcm16_muxer;
+extern const FFOutputFormat ff_mcm_audio_pcm24_muxer;
extern const FFInputFormat ff_android_camera_demuxer;
extern const FFOutputFormat ff_audiotoolbox_muxer;
extern const FFInputFormat ff_avfoundation_demuxer;
--
2.45.1.windows.1
2.34.1

60 changes: 13 additions & 47 deletions ffmpeg-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,22 @@ udp://@:1234

The table below shows a proper way to configure the sender and the receiver depending on the audio PCM encoding format

| Audio encoding | Sender configuration | Receiver configuration |
| --- | --- | --- |
| PCM 24-bit | Output device `mcm_audio` | Input device `mcm_audio` and argument `-pcm_fmt pcm24`
| PCM 16-bit | Output device `mcm_audio_pcm16` | Input device `mcm_audio` and argument `-pcm_fmt pcm16`
| Audio encoding | Sender configuration | Receiver configuration |
| -------------- | ------------------------------- | ------------------------------ |
| PCM 16-bit | Output device `mcm_audio_pcm16` | Input device `mcm_audio_pcm16` |
| PCM 24-bit | Output device `mcm_audio_pcm24` | Input device `mcm_audio_pcm24` |

The next arguments are supported to configure an audio transmission

| Argument | Type | Description | Default |
| ------------- | :-----: | ------------------------------------------------ | :-------: |
| `channels` | Integer | Number of audio channels (`1`, `2`, etc.) | `2` |
| `sample_rate` | Integer | Audio sample rate (`44100`, `48000`, or `96000`) | `48000` |
| `ptime` | String | MTL audio packet time (`"1ms"` or `"125us"`) | `"1ms"` |
| `pcm_fmt` | String | PCM audio format (`"pcm24"` or `"pcm16"`) | `"pcm24"` |
| Argument | Type | Description | Default |
| ------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------: |
| `channels` | Integer | Number of audio channels (`1`, `2`, etc.) | `2` |
| `sample_rate` | Integer | Audio sample rate (`44100`, `48000`, or `96000`) | `48000` |
| `ptime` | String | Audio packet time according to ST2110-30. For 48000 and 96000 sampling: `"1ms"`, `"125us"`, `"250us"`, `"333us"`, `"4ms"`, or `"80us"`. For 44100 sampling: `"1.09ms"`, `"0.14ms"`, or `"0.09ms"` | `"1ms"` |

## Example – Run audio transmission
## Example – Run audio transmission, PCM 24-bit

This example demonstrates sending an audio file from the 1st FFmpeg instance to the 2nd FFmpeg instance via MCM.

There are two options of configuration:
* **Option A** for PCM 24-bit encoded audio
* **Option B** for PCM 16-bit encoded audio
This example demonstrates sending a PCM 24-bit encoded audio file from the 1st FFmpeg instance to the 2nd FFmpeg instance via MCM.

### NIC setup

Expand All @@ -140,27 +135,11 @@ TBD
```
2. Start FFmpeg to receive packets from MCM and store on the disk

**Option A – PCM 24-bit audio**
```bash
sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg -re -f mcm_audio \
-channels 2 \
-sample_rate 48000 \
-ptime 1ms \
-pcm_fmt pcm24 \
-protocol_type auto \
-payload_type st30 \
-ip_addr 192.168.96.1 \
-port 9001 \
-i - output.wav
```

**Option B – PCM 16-bit audio**
```bash
sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg -re -f mcm_audio \
sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg -re -f mcm_audio_pcm24 \
-channels 2 \
-sample_rate 48000 \
-ptime 1ms \
-pcm_fmt pcm16 \
-protocol_type auto \
-payload_type st30 \
-ip_addr 192.168.96.1 \
Expand All @@ -176,21 +155,8 @@ TBD
```
2. Start FFmpeg to stream an audio file to the receiver via MCM

**Option A – PCM 24-bit audio**
```bash
sudo MCM_MEDIA_PROXY_PORT=8001 ffmpeg -i <audio-file-path> -f mcm_audio \
-channels 2 \
-sample_rate 48000 \
-ptime 1ms \
-protocol_type auto \
-payload_type st30 \
-ip_addr 192.168.96.2 \
-port 9001 -
```

**Option B – PCM 16-bit audio**
```bash
sudo MCM_MEDIA_PROXY_PORT=8001 ffmpeg -i <audio-file-path> -f mcm_audio_pcm16 \
sudo MCM_MEDIA_PROXY_PORT=8001 ffmpeg -i <audio-file-path> -f mcm_audio_pcm24 \
-channels 2 \
-sample_rate 48000 \
-ptime 1ms \
Expand Down
Loading

0 comments on commit 2b1a469

Please sign in to comment.