当前位置: 首页 > news >正文

什么是小手机型网站seo常用工具有哪些

什么是小手机型网站,seo常用工具有哪些,创新的响应式网站建设,装饰行业模板网站目录 学习课题#xff1a;逐步构建开发播放器【QT5 FFmpeg6 SDL2】 步骤 AudioOutPut模块 1、初始化【分配缓存、读取信息】 2、开始线程工作【从队列读帧-重采样-SDL回调-写入音频播放数据-SDL进行播放】 主要代码 分配缓存 // 对于样本队列 av_audio_…目录 学习课题逐步构建开发播放器【QT5 FFmpeg6 SDL2】 步骤 AudioOutPut模块 1、初始化【分配缓存、读取信息】 2、开始线程工作【从队列读帧-重采样-SDL回调-写入音频播放数据-SDL进行播放】 主要代码 分配缓存 // 对于样本队列 av_audio_fifo_alloc(playSampleFmt, playChannels, spec.samples * 5);// 对于帧的音频字节数据 // 首次计算帧大小并且开辟缓冲区 maxOutSamples (int) av_rescale_rnd(decCtxSamples, playSampleRate, srcSampleRate, AV_ROUND_UP); audioBufferSize av_samples_get_buffer_size(nullptr, srcChannels, maxOutSamples, playSampleFmt, 0); audioBuffer (uint8_t *) av_malloc(audioBufferSize); 重采样相关 //配置重采样器参数 swr_alloc_set_opts2(swrContext,srcChannelLayout, playSampleFmt, playSampleRate,srcChannelLayout, AVSampleFormat(srcSampleFmt), srcSampleRate,0, nullptr); //初始化重采样器 swr_init(swrContext);//重采样流程 // 计算重采样后要输出多少样本数delay swr_get_delay(swrContext, sample_rate);out_samples (int) av_rescale_rnd(nb_samples delay,playSampleRate,sample_rate,AV_ROUND_DOWN);// 判断预测的输出样本数是否本次任务的最大样本数if (out_samples maxOutSamples) {// 释放缓冲区重新初始化缓冲区大小av_freep(audioBuffer);audioBufferSize av_samples_get_buffer_size(nullptr, srcChannels, out_samples, playSampleFmt, 0);audioBuffer (uint8_t *) av_malloc(audioBufferSize);maxOutSamples out_samples;}playSamples swr_convert(swrContext, audioBuffer, out_samples, (const uint8_t **) frame-data, nb_samples); SDL的音频回调 // SDL音频回调函数提供了一个回调接口可以让我们在音频设备需要数据的时候向里面写入数据 // 从而进行声音播放 // 回调函数示例 函数名自定义放在类中需要加静态(static) void AudioOutPut::AudioCallBackFunc(void *userdata, Uint8 *stream, int len) {//userdata 是在初始化时赋值的有时候会把类中this传进去//stream 是音频流在回调函数中需要把音频数据写入到stream就可以实现声音播放//len是由SDL传入的SDL缓冲区的大小如果这个缓冲未满我们就一直往里填充数据... } 完整模块 AudioOutPut //AudioOutPut.h #include FFmpegHeader.h #include SDL.h #include queue/AVFrameQueue.h #include QDebug #include QObject #include QtGui #include QtWidgets #include threadclass AudioOutPut { private:std::thread *m_thread;bool isStopped true; // 是否已经停止 停止时退出线程bool isPlaying false;// 是否正在播放bool isPause false; // 是否暂停void run();int resampleFrame(AVFrame *frame);int sdlCallBackMode 1;QString url; //视频地址uint8_t *audioBuffer; //存储解码后音频bufferint audioBufferSize 0;//buffer大小int audioBufferIndex 0;SDL_mutex *mtx nullptr;// 队列锁SDL_AudioDeviceID audioDevice;AVAudioFifo *fifo nullptr;//Audio BufferAVFrameQueue *frameQueue; //解码后的帧队列SwrContext *swrContext; //重采样上下文// 解码器上下文AVCodecContext *decCtx; // 音频解码器上下文int srcChannels; // 源通道数AVChannelLayout srcChannelLayout;// 源通道布局enum AVSampleFormat srcSampleFmt;// 源采样格式int srcSampleRate; // 源音频采样率// playerint maxOutSamples; // 最大样本数用于计算缓存区大小int playSamples; // 最终播放的样本数int playSampleRate;// 最终播放的音频采样率enum AVSampleFormat playSampleFmt;int playChannels;// 源通道数 public:AudioOutPut(AVCodecContext *dec_ctx, AVFrameQueue *frame_queue);int init(int mode 1);static void AudioCallBackFunc(void *userdata, Uint8 *stream, int len);//SDL音频回调函数实体普通版void AudioCallBack(Uint8 *stream, int len);//SDL音频回调函数实体队列版void AudioCallBackFromQueue(Uint8 *stream, int len);int start(); };//AudioOutPut.cpp #include AudioOutPut.h AudioOutPut::AudioOutPut(AVCodecContext *dec_ctx, AVFrameQueue *frame_queue): decCtx(dec_ctx), frameQueue(frame_queue) {srcSampleFmt decCtx-sample_fmt;srcSampleRate decCtx-sample_rate;srcChannelLayout decCtx-ch_layout;srcChannels srcChannelLayout.nb_channels; } int AudioOutPut::init(int mode) {sdlCallBackMode mode;// SDL initif (SDL_Init(SDL_INIT_AUDIO) ! 0) {qDebug() SDL_INIT_AUDIO error;return -1;}SDL_AudioSpec wanted_spec, spec;wanted_spec.channels decCtx-ch_layout.nb_channels;wanted_spec.freq decCtx-sample_rate;SDL_AudioFormat sample_type;switch (srcSampleFmt) {case AV_SAMPLE_FMT_FLTP:case AV_SAMPLE_FMT_FLT:sample_type AUDIO_F32SYS;break;case AV_SAMPLE_FMT_U8P:case AV_SAMPLE_FMT_U8:sample_type AUDIO_U8;break;case AV_SAMPLE_FMT_S64P:case AV_SAMPLE_FMT_S64:case AV_SAMPLE_FMT_S32P:case AV_SAMPLE_FMT_S32:sample_type AUDIO_S32SYS;break;case AV_SAMPLE_FMT_S16P:case AV_SAMPLE_FMT_S16:sample_type AUDIO_S16SYS;break;default:sample_type AUDIO_S16SYS;qDebug() 不支持的采样格式:AVSampleFormat( srcSampleFmt );}wanted_spec.format sample_type;wanted_spec.silence 0;wanted_spec.callback AudioCallBackFunc;wanted_spec.userdata this;wanted_spec.samples decCtx-frame_size;int ret;// ret SDL_OpenAudio(wanted_spec, spec);audioDevice SDL_OpenAudioDevice(NULL, 0, wanted_spec, spec, SDL_AUDIO_ALLOW_ANY_CHANGE);if (audioDevice 0) {qDebug() SDL_OpenAudio error;return -1;}playChannels spec.channels;playSampleRate spec.freq;playSampleFmt av_get_packed_sample_fmt(srcSampleFmt);if (mode 1) {fifo av_audio_fifo_alloc(playSampleFmt, playChannels, spec.samples * 5);}ret swr_alloc_set_opts2(swrContext,srcChannelLayout, playSampleFmt, playSampleRate,srcChannelLayout, AVSampleFormat(srcSampleFmt), srcSampleRate,0, nullptr);if (ret ! 0) {qDebug() swr_alloc_set_opts2错误;return -1;}if (!swrContext) {qDebug() 创建音频重采样上下文错误 swr_alloc;return -1;}ret swr_init(swrContext);if (ret 0) {qDebug() 初始化音频重采样上下文错误 swr_init;return -1;}// 解码器上下文保存的帧样本数int decCtxSamples 1024;if (decCtx-frame_size 1024) {decCtxSamples decCtx-frame_size;}// 首次计算帧大小并且开辟缓冲区maxOutSamples (int) av_rescale_rnd(decCtxSamples, playSampleRate, srcSampleRate, AV_ROUND_UP);audioBufferSize av_samples_get_buffer_size(nullptr, srcChannels, maxOutSamples, playSampleFmt, 0);audioBuffer (uint8_t *) av_malloc(audioBufferSize);return 1; }void AudioOutPut::AudioCallBackFunc(void *userdata, Uint8 *stream, int len) {AudioOutPut *player (AudioOutPut *) userdata;if (player-sdlCallBackMode 1) {player-AudioCallBackFromQueue(stream, len);} else {player-AudioCallBack(stream, len);} }void AudioOutPut::AudioCallBack(Uint8 *stream, int len) {int len1;// sdl的内部stream可用空间/* len是由SDL传入的SDL缓冲区的大小如果这个缓冲未满我们就一直往里填充数据 */while (len 0) {/* audioBufferIndex 和 audioBufferSize 标示我们自己用来放置解码出来的数据的缓冲区*//* 这些数据待copy到SDL缓冲区 当audioBufferIndex audioBufferSize的时候意味着我*//* 们的缓冲为空没有数据可供copy这时候需要调用audio_decode_frame来解码出更多的桢数据 */if (audioBufferIndex audioBufferSize) {AVFrame *frame frameQueue-pop(10);if (frame) {audioBufferSize resampleFrame(frame);/* audioBufferSize 0 标示没能解码出数据我们默认播放静音 */if (audioBufferSize 0) {/* silence */audioBufferSize 1024;/* 清零静音 */memset(audioBuffer, 0, audioBufferSize);}}audioBufferIndex 0;}/* 当audioBufferIndex audioBufferSize 查看stream可用空间决定一次copy多少数据剩下的下次继续copy */len1 audioBufferSize - audioBufferIndex;// 可用空间if (len1 len) {len1 len;}if (audioBuffer nullptr) return;memcpy(stream, (uint8_t *) audioBuffer audioBufferIndex, len1);len - len1;stream len1;audioBufferIndex len1;} }void AudioOutPut::AudioCallBackFromQueue(Uint8 *stream, int len) {//由于AVAudioFifo非线程安全且是子线程触发此回调所以需要加锁SDL_LockMutex(mtx);//读取队列中的音频数据av_audio_fifo_read(fifo, (void **) stream, playSamples);SDL_UnlockMutex(mtx); } int AudioOutPut::start() {SDL_PauseAudioDevice(audioDevice, 0);// SDL_PauseAudio(0);if (sdlCallBackMode 1) {m_thread new std::thread(AudioOutPut::run, this);if (!m_thread-joinable()) {qDebug() AudioOutPut音频帧处理线程创建失败;return -1;}}isStopped false;isPlaying true;return 0; } void AudioOutPut::run() {AVFrame *frame;while (!isStopped) {frame frameQueue-pop(10);if (frame) {audioBufferSize resampleFrame(frame);while (true) {SDL_LockMutex(mtx);if (av_audio_fifo_space(fifo) playSamples) {av_audio_fifo_write(fifo, (void **) audioBuffer, playSamples);SDL_UnlockMutex(mtx);av_frame_unref(frame);break;}SDL_UnlockMutex(mtx);//队列可用空间不足则延时等待SDL_Delay((double) playSamples / playSampleRate);}}} } int AudioOutPut::resampleFrame(AVFrame *frame) {int64_t delay; // 重采样后延迟int out_samples;// 预测的重采样后的输出样本数int sample_rate;// 帧原采样率int nb_samples; // 帧原样本数sample_rate frame-sample_rate;nb_samples frame-nb_samples;// 计算重采样后要输出多少样本数delay swr_get_delay(swrContext, sample_rate);out_samples (int) av_rescale_rnd(nb_samples delay,playSampleRate,sample_rate,AV_ROUND_DOWN);// 判断预测的输出样本数是否本次任务的最大样本数if (out_samples maxOutSamples) {// 释放缓冲区重新初始化缓冲区大小av_freep(audioBuffer);audioBufferSize av_samples_get_buffer_size(nullptr, srcChannels, out_samples, playSampleFmt, 0);audioBuffer (uint8_t *) av_malloc(audioBufferSize);maxOutSamples out_samples;}playSamples swr_convert(swrContext, audioBuffer, out_samples, (const uint8_t **) frame-data, nb_samples);if (playSamples 0) {return -1;}return av_samples_get_buffer_size(nullptr, srcChannels, playSamples, playSampleFmt, 1); } PlayerMain 添加音频输出代码 AudioOutPut *audioOutPut; audioOutPut new AudioOutPut(audioDecodeThread-dec_ctx, audioFrameQueue); audioOutPut-init(1); audioOutPut-start(); 测试运行结果 如果需要同时执行视频和音频的输出记得要在解复用模块那把限制队列大小的位置把视频队列的大小限制给去掉。 目前只是实现了音频播放和视频渲染显示画面但是可以看到音频和视频是不同步的下一章我们就要让音频和视频同步起来。 播放器开发(六)音频帧处理并用SDL播放结果
http://www.zqtcl.cn/news/649511/

相关文章:

  • 做一家算命的网站有没有专门做淘宝客的网站
  • 网站站点管理在哪里建筑施工图设计
  • 众筹网站开发周期网页云原神
  • 哪些网站可以免费做h5东莞制作企业网站
  • 帝国cms 网站地址设置深圳住房和建设部网站
  • 专业网站建设价格最优网页游戏大全电脑版在线玩
  • 建设租车网站wordpress+js插件开发
  • 定制网站开发与模板商务酒店设计网站建设
  • php 网站部署后乱码wordpress禁止调用头部
  • 网站权重低营销型企业网站建站
  • 大港油田建设网站长春市网站优化公司
  • 嘉峪关市建设局建管科资质网站室内设计入门教程
  • 久久建筑网会员登陆中心百度的搜索引擎优化
  • 做网站好还是做程序员好wordpress new图标
  • 秀洲住房与建设局网站徐州建设工程招投标官方网站
  • 做公司网站要注意哪些问题做章的网站
  • 南京建设网站维护洛阳最新通告今天
  • 网站名称创意大全wordpress公开课插件
  • 淮安市城市建设档案馆网站可以做网页的软件
  • 网站空间服务器wordpress 排除置顶文章
  • 有域名后怎么做网站邯郸做移动网站的地方
  • 商标可以做网站吗网站开发的大学生应届简历
  • 长沙长沙网站建设公司saas系统架构
  • 成都销售型网站长春财经学院多大
  • 手机自己制作表白网站app项目网络计划图怎么画
  • 品牌网站如何做seo浏览器正能量网址
  • 开封做网站哪家好网页设计制作网站大一素材
  • 河南网站域名备案莱芜新闻电视台节目表
  • 长春网站建设新格做天猫还是做网站推广
  • 新网站建设的感想安阳区号是什么