Skip to content

Commit

Permalink
Merge branch 'master' into ci_test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbraveyoung authored Aug 4, 2023
2 parents ace6d28 + 56a349d commit 0b4ff00
Show file tree
Hide file tree
Showing 159 changed files with 15,834 additions and 16,855 deletions.
595 changes: 295 additions & 300 deletions bmf/c_modules/include/fraction.hpp

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions bmf/c_modules/src/audio_fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

#include "audio_fifo.h"

AudioFifo::AudioFifo(int format, int channels, uint64_t channel_layout, AVRational time_base, int sample_rate) {
AudioFifo::AudioFifo(int format, int channels, uint64_t channel_layout,
AVRational time_base, int sample_rate) {
format_ = format;
channels_ = channels;
audio_fifo_ = av_audio_fifo_alloc((AVSampleFormat) format, channels, 2048);
audio_fifo_ = av_audio_fifo_alloc((AVSampleFormat)format, channels, 2048);
time_base_ = time_base;
channel_layout_ = channel_layout;
sample_rate_ = sample_rate;
Expand All @@ -26,7 +27,8 @@ AudioFifo::AudioFifo(int format, int channels, uint64_t channel_layout, AVRation
BMFLOG(BMF_ERROR) << "Could not allocate audio_fifo_";
}

int AudioFifo::read(int samples, bool partial, bool &got_frame, AVFrame *&frame) {
int AudioFifo::read(int samples, bool partial, bool &got_frame,
AVFrame *&frame) {
int ret;
got_frame = false;
int buffered_samples = av_audio_fifo_size(audio_fifo_);
Expand All @@ -49,23 +51,25 @@ int AudioFifo::read(int samples, bool partial, bool &got_frame, AVFrame *&frame)
BMFLOG(BMF_ERROR) << "Error allocating an audio buffer";
return ret;
}
int read_samples = av_audio_fifo_read(audio_fifo_, (void **) (frame->extended_data), samples);
int read_samples = av_audio_fifo_read(
audio_fifo_, (void **)(frame->extended_data), samples);
if (read_samples < 0) {
BMFLOG(BMF_ERROR) << "av_audio_fifo_read " << read_samples;
return read_samples;
}
got_frame = true;
frame->nb_samples = read_samples;
if (first_pts_ != AV_NOPTS_VALUE) {
frame->pts = (int64_t) (pts_per_sample_ * samples_read_) + first_pts_;
frame->pts = (int64_t)(pts_per_sample_ * samples_read_) + first_pts_;
} else {
frame->pts = AV_NOPTS_VALUE;
}
samples_read_ += read_samples;
return 0;
}

int AudioFifo::read_many(int samples, bool partial, std::vector<AVFrame *> &frame_list) {
int AudioFifo::read_many(int samples, bool partial,
std::vector<AVFrame *> &frame_list) {
while (1) {
AVFrame *frame = NULL;
frame = av_frame_alloc();
Expand Down Expand Up @@ -93,7 +97,8 @@ int AudioFifo::write(AVFrame *frame) {
first_pts_ = frame->pts;
first_frame_ = false;
}
ret = av_audio_fifo_write(audio_fifo_, (void **) (frame->extended_data), frame->nb_samples);
ret = av_audio_fifo_write(audio_fifo_, (void **)(frame->extended_data),
frame->nb_samples);
return ret;
}

Expand Down
39 changes: 24 additions & 15 deletions bmf/c_modules/src/audio_resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
*/
#include "audio_resampler.h"

AudioResampler::AudioResampler(int input_format, int output_format, int input_channel_layout, int output_channel_layout,
int input_sample_rate, int output_sample_rate, AVRational input_time_base,
AudioResampler::AudioResampler(int input_format, int output_format,
int input_channel_layout,
int output_channel_layout, int input_sample_rate,
int output_sample_rate,
AVRational input_time_base,
AVRational output_time_base) {
int ret;
input_format_ = input_format;
Expand All @@ -36,7 +39,7 @@ AudioResampler::AudioResampler(int input_format, int output_format, int input_ch
av_opt_set_int(swr_ctx_, "in_sample_rate", input_sample_rate, 0);
av_opt_set_int(swr_ctx_, "out_sample_rate", output_sample_rate, 0);
ret = swr_init(swr_ctx_);
ratio_ = (double) output_sample_rate / input_sample_rate;
ratio_ = (double)output_sample_rate / input_sample_rate;
if (ret < 0)
BMFLOG(BMF_ERROR) << "init swr failed:" << ret;
return;
Expand Down Expand Up @@ -72,35 +75,41 @@ int AudioResampler::resample(AVFrame *insamples, AVFrame *&outsamples) {
return 0;
}


// get output samples pts
if (insamples) {
if (insamples->pts != AV_NOPTS_VALUE && input_time_base_.num != -1) {

//translate pts to timestamps which is in 1/(in_sample_rate * out_sample_rate) units.
int64_t inpts = av_rescale(insamples->pts, input_time_base_.num *
output_sample_rate_ * insamples->sample_rate,
input_time_base_.den);
// get outpts whose timestamps is 1/(in_sample_rate * out_sample_rate)
// translate pts to timestamps which is in 1/(in_sample_rate *
// out_sample_rate) units.
int64_t inpts = av_rescale(
insamples->pts, input_time_base_.num * output_sample_rate_ *
insamples->sample_rate,
input_time_base_.den);
// get outpts whose timestamps is 1/(in_sample_rate *
// out_sample_rate)
int64_t outpts = swr_next_pts(swr_ctx_, inpts);

// translate pts to timestamps is output_time_base;
outsamples->pts = av_rescale(outpts, output_time_base_.den,
output_time_base_.num * output_sample_rate_ * insamples->sample_rate);
outsamples->pts =
av_rescale(outpts, output_time_base_.den,
output_time_base_.num * output_sample_rate_ *
insamples->sample_rate);
} else {
outsamples->pts = AV_NOPTS_VALUE;
}
} else {
int64_t outpts = swr_next_pts(swr_ctx_, INT64_MIN);
outsamples->pts = av_rescale(outpts, output_time_base_.den,
output_time_base_.num * output_sample_rate_ * input_sample_rate_);
outsamples->pts = av_rescale(
outpts, output_time_base_.den,
output_time_base_.num * output_sample_rate_ * input_sample_rate_);
}

uint8_t **input_data = NULL;
if (insamples != NULL) {
input_data = (uint8_t **) insamples->extended_data;
input_data = (uint8_t **)insamples->extended_data;
}
n_out = swr_convert(swr_ctx_, outsamples->extended_data, n_out, (const uint8_t**)input_data, n_in);
n_out = swr_convert(swr_ctx_, outsamples->extended_data, n_out,
(const uint8_t **)input_data, n_in);
if (n_out <= 0) {
return n_out;
}
Expand Down
13 changes: 6 additions & 7 deletions bmf/c_modules/src/clock_module.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../include/clock_module.h"


#include <unistd.h>

#include <string>
Expand Down Expand Up @@ -32,7 +31,8 @@ ClockModule::ClockModule(int node_id, JsonParam option) {
int ClockModule::process(Task &task) {
auto now = std::chrono::high_resolution_clock::now();

if (lst_ts_.time_since_epoch() == std::chrono::high_resolution_clock::duration::zero()) {
if (lst_ts_.time_since_epoch() ==
std::chrono::high_resolution_clock::duration::zero()) {
lst_ts_ = now;
} else if (now - lst_ts_ < tick_) {
// Can be 10us quicker, in order to decrease delay.
Expand All @@ -43,14 +43,13 @@ int ClockModule::process(Task &task) {

lst_ts_ += tick_;
Packet pkt(0);
pkt.set_timestamp((fps_tick_ * frm_cnt_++).to_int_based(time_base_) * 1000000);
//pkt.set_timestamp((fps_tick_ * frm_cnt_++).to_int_based(time_base_));
pkt.set_timestamp((fps_tick_ * frm_cnt_++).to_int_based(time_base_) *
1000000);
// pkt.set_timestamp((fps_tick_ * frm_cnt_++).to_int_based(time_base_));
task.fill_output_packet(0, pkt);
return 0;
}

bool ClockModule::is_hungry(int input_stream_id) {
return true;
}
bool ClockModule::is_hungry(int input_stream_id) { return true; }

REGISTER_MODULE_CLASS(ClockModule)
Loading

0 comments on commit 0b4ff00

Please sign in to comment.