Skip to content

Commit

Permalink
Trying to fix MP4 audio playback in-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 12, 2024
1 parent f9151e0 commit d815fda
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ int enable_mp4(void) {

mp4_set_config(app_config.mp4_width, app_config.mp4_height, app_config.mp4_fps,
app_config.audio_enable ? HAL_AUDCODEC_MP3 : HAL_AUDCODEC_UNSPEC,
app_config.audio_bitrate, app_config.audio_srate);
app_config.audio_bitrate, 1, app_config.audio_srate);
}

if (ret = bind_channel(index, app_config.mp4_fps, 0))
Expand Down
8 changes: 4 additions & 4 deletions src/mp4/moov.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ enum BufError write_btrt(struct BitBuf *ptr, const struct MoovInfo *moov_info) {
chk_err; // 4 Buffer size
err = put_u32_be(ptr, moov_info->audio_bitrate * 1000);
chk_err; // 4 Max bitrate
err = put_u32_be(ptr, moov_info->audio_bitrate * 1000);
err = put_u32_be(ptr, moov_info->audio_bitrate * 1000 - 1);
chk_err; // 4 Avg bitrate
err = put_u32_be_to_offset(ptr, start_atom, ptr->offset - start_atom);
chk_err;
Expand Down Expand Up @@ -619,7 +619,7 @@ enum BufError write_DecoderConfig(struct BitBuf *ptr, const struct MoovInfo *moo
chk_err; // 3 bufferSize
err = put_u32_be(ptr, moov_info->audio_bitrate * 1000);
chk_err; // 4 Max bitrate
err = put_u32_be(ptr, moov_info->audio_bitrate * 1000);
err = put_u32_be(ptr, moov_info->audio_bitrate * 1000 - 1);
chk_err; // 4 Avg bitrate
err = put_u32_le_to_offset(ptr, var_len, varint32(ptr->offset - var_len - 4));
chk_err;
Expand Down Expand Up @@ -675,7 +675,7 @@ enum BufError write_TagAudioSpecificConfig(
bitstream |= moov_info->audio_samplerate;
used_bits += 24;
}
int channels = 1;
int channels = moov_info->audio_channels;
bitstream <<= 4;
bitstream |= channels;
used_bits += 4;
Expand Down Expand Up @@ -768,7 +768,7 @@ enum BufError write_mp4a(struct BitBuf *ptr, const struct MoovInfo *moov_info) {
chk_err; // 1 dataref index
err = put_skip(ptr, 8);
chk_err; // 8 reserved
err = put_u16_be(ptr, 2);
err = put_u16_be(ptr, moov_info->audio_channels);
chk_err; // 2 channel count
err = put_u16_be(ptr, 16);
chk_err; // 2 sample size
Expand Down
1 change: 1 addition & 0 deletions src/mp4/moov.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
struct MoovInfo {
char audio_codec;
unsigned short audio_bitrate;
unsigned char audio_channels;
unsigned int audio_samplerate;
char is_h265;
uint8_t profile_idc;
Expand Down
8 changes: 6 additions & 2 deletions src/mp4/mp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ uint32_t default_sample_size = 40000;

unsigned int aud_samplerate = 0;
unsigned short aud_bitrate = 0;
char aud_channels = 0;
short vid_width = 1920, vid_height = 1080;
char aud_codec = 0, vid_framerate = 30;

Expand Down Expand Up @@ -35,6 +36,8 @@ enum BufError create_header(char is_h265) {
struct MoovInfo moov_info;
memset(&moov_info, 0, sizeof(struct MoovInfo));
moov_info.audio_codec = aud_codec;
moov_info.audio_bitrate = aud_bitrate;
moov_info.audio_channels = aud_channels;
moov_info.audio_samplerate = aud_samplerate;
moov_info.is_h265 = is_h265 & 1;
moov_info.profile_idc = 100;
Expand All @@ -59,13 +62,14 @@ enum BufError create_header(char is_h265) {
chk_err return BUF_OK;
}

void mp4_set_config(short width, short height, char framerate,
char acodec, unsigned short bitrate, unsigned int srate) {
void mp4_set_config(short width, short height, char framerate, char acodec,
unsigned short bitrate, char channels, unsigned int srate) {
vid_width = width;
vid_height = height;
vid_framerate = framerate;
aud_codec = acodec;
aud_bitrate = bitrate;
aud_channels = channels;
aud_samplerate = srate;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mp4/mp4.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct Mp4State {
uint32_t nals_count;
};

void mp4_set_config(short width, short height, char framerate,
char acodec, unsigned short bitrate, unsigned int srate);
void mp4_set_config(short width, short height, char framerate, char acodec,
unsigned short bitrate, char channels, unsigned int srate);

void mp4_set_sps(const char *nal_data, const uint32_t nal_len, char is_h265);
void mp4_set_pps(const char *nal_data, const uint32_t nal_len, char is_h265);
Expand Down

0 comments on commit d815fda

Please sign in to comment.