AI: Fix AAC audio sample rate reporting in API. v7.0.101 (#4518)

This commit is contained in:
OSSRS-AI 2025-10-22 21:28:40 -04:00 committed by winlin
parent 0e28422d12
commit 0c9868b4a2
5 changed files with 50 additions and 3 deletions

View File

@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v7-changes"></a>
## SRS 7.0 Changelog
* v7.0, 2025-11-04, AI: Fix AAC audio sample rate reporting in API. v7.0.101 (#4518)
* v7.0, 2025-10-20, Merge [#4537](https://github.com/ossrs/srs/pull/4537): Forward: Reject RTMPS destinations with clear error message. v7.0.100 (#4537)
* v7.0, 2025-10-17, Merge [#4534](https://github.com/ossrs/srs/pull/4534): HLS: Fix a iterator bug in hls_ctx cleanup function. v7.0.99 (#4534)
* v7.0, 2025-10-16, Merge [#4530](https://github.com/ossrs/srs/pull/4530): fix crash issue caused by reload configuration file. v7.0.98 (#4530)

View File

@ -997,7 +997,14 @@ srs_error_t SrsOriginHub::on_audio(SrsMediaPacket *shared_audio)
static int flv_sound_types[] = {1, 2, 0};
// when got audio stream info.
if ((err = stat_->on_audio_info(req_, format->acodec_->id_, c->sound_rate_, c->sound_type_, c->aac_object_)) != srs_success) {
// For AAC, convert aac_sample_rate_ index to SrsAudioSampleRate enum
// For MP3 and other codecs, use sound_rate_ directly (FLV enum)
SrsAudioSampleRate sample_rate = c->sound_rate_;
if (format->acodec_->id_ == SrsAudioCodecIdAAC && c->aac_sample_rate_ < SrsAAcSampleRateNumbers) {
sample_rate = srs_audio_sample_rate_from_number(srs_aac_srates[c->aac_sample_rate_]);
}
if ((err = stat_->on_audio_info(req_, format->acodec_->id_, sample_rate, c->sound_type_, c->aac_object_)) != srs_success) {
return srs_error_wrap(err, "stat audio");
}

View File

@ -166,7 +166,7 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject *obj)
obj->set("audio", audio);
audio->set("codec", SrsJsonAny::str(srs_audio_codec_id2str(acodec_).c_str()));
audio->set("sample_rate", SrsJsonAny::integer(srs_flv_srates[asample_rate_]));
audio->set("sample_rate", SrsJsonAny::integer(srs_audio_sample_rate2number(asample_rate_)));
audio->set("channel", SrsJsonAny::integer(asound_type_ + 1));
audio->set("profile", SrsJsonAny::str(srs_aac_object2str(aac_object_).c_str()));
}

View File

@ -9,6 +9,6 @@
#define VERSION_MAJOR 7
#define VERSION_MINOR 0
#define VERSION_REVISION 100
#define VERSION_REVISION 101
#endif

View File

@ -3012,6 +3012,45 @@ VOID TEST(StatisticTest, StreamMediaInfo)
EXPECT_EQ(55, stream->frames_->sugar_);
}
// Test SrsStatistic audio sample rate handling for AAC 48000 Hz
// This test verifies the fix for issue #4518 - API should report correct sample rate for AAC streams
VOID TEST(StatisticTest, AudioSampleRateAAC48000Hz)
{
srs_error_t err = srs_success;
// Create SrsStatistic instance
SrsUniquePtr<SrsStatistic> stat(new SrsStatistic());
// Create mock request for testing
SrsUniquePtr<MockSrsRequest> req(new MockSrsRequest("test.vhost", "live", "stream_48k"));
// Test on_audio_info() with AAC 48000 Hz sample rate
HELPER_EXPECT_SUCCESS(stat->on_audio_info(req.get(), SrsAudioCodecIdAAC, SrsAudioSampleRate48000, SrsAudioChannelsStereo, SrsAacObjectTypeAacLC));
// Verify audio info was set correctly
SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url());
EXPECT_TRUE(stream != NULL);
EXPECT_TRUE(stream->has_audio_);
EXPECT_EQ(SrsAudioCodecIdAAC, stream->acodec_);
EXPECT_EQ(SrsAudioSampleRate48000, stream->asample_rate_);
EXPECT_EQ(SrsAudioChannelsStereo, stream->asound_type_);
EXPECT_EQ(SrsAacObjectTypeAacLC, stream->aac_object_);
// Verify JSON dumps reports correct sample rate (48000 Hz, not 44100 Hz)
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
HELPER_EXPECT_SUCCESS(stream->dumps(obj.get()));
// Check that audio object exists and has correct sample_rate
SrsJsonAny *audio_any = obj->get_property("audio");
EXPECT_TRUE(audio_any != NULL);
EXPECT_TRUE(audio_any->is_object());
SrsJsonObject *audio = audio_any->to_object();
SrsJsonAny *sample_rate_any = audio->get_property("sample_rate");
EXPECT_TRUE(sample_rate_any != NULL);
EXPECT_EQ(48000, sample_rate_any->to_integer());
}
// Test SrsStatistic dumps methods: dumps_streams, dumps_clients, and dumps_hints_kv
// This test covers the major use scenario for dumping statistics to JSON and hints
VOID TEST(StatisticTest, DumpsStreamsClientsAndHints)