Opus codec module test pass

This commit is contained in:
dijunkun
2023-11-29 19:16:12 -08:00
parent d79720532d
commit 3a1be00ca5
41 changed files with 1243 additions and 177 deletions

92
src/frame/audio_frame.cpp Normal file
View File

@@ -0,0 +1,92 @@
#include "audio_frame.h"
#include <string.h>
#include <string>
AudioFrame::AudioFrame() {}
AudioFrame::AudioFrame(size_t size) {
buffer_ = new uint8_t[size];
size_ = size;
width_ = 0;
height_ = 0;
}
AudioFrame::AudioFrame(const uint8_t *buffer, size_t size) {
buffer_ = new uint8_t[size];
memcpy(buffer_, buffer, size);
size_ = size;
width_ = 0;
height_ = 0;
}
AudioFrame::AudioFrame(const uint8_t *buffer, size_t size, size_t width,
size_t height) {
buffer_ = new uint8_t[size];
memcpy(buffer_, buffer, size);
size_ = size;
width_ = width;
height_ = height;
}
AudioFrame::AudioFrame(const AudioFrame &audio_frame) {
if (audio_frame.size_ > 0) {
buffer_ = new uint8_t[audio_frame.size_];
memcpy(buffer_, audio_frame.buffer_, audio_frame.size_);
size_ = audio_frame.size_;
width_ = audio_frame.width_;
height_ = audio_frame.height_;
}
}
AudioFrame::AudioFrame(AudioFrame &&audio_frame)
: buffer_((uint8_t *)std::move(audio_frame.buffer_)),
size_(audio_frame.size_),
width_(audio_frame.width_),
height_(audio_frame.height_) {
audio_frame.buffer_ = nullptr;
audio_frame.size_ = 0;
audio_frame.width_ = 0;
audio_frame.height_ = 0;
}
AudioFrame &AudioFrame::operator=(const AudioFrame &audio_frame) {
if (&audio_frame != this) {
if (buffer_) {
delete buffer_;
buffer_ = nullptr;
}
buffer_ = new uint8_t[audio_frame.size_];
memcpy(buffer_, audio_frame.buffer_, audio_frame.size_);
size_ = audio_frame.size_;
width_ = audio_frame.width_;
height_ = audio_frame.height_;
}
return *this;
}
AudioFrame &AudioFrame::operator=(AudioFrame &&audio_frame) {
if (&audio_frame != this) {
buffer_ = std::move(audio_frame.buffer_);
audio_frame.buffer_ = nullptr;
size_ = audio_frame.size_;
audio_frame.size_ = 0;
width_ = audio_frame.width_;
audio_frame.width_ = 0;
height_ = audio_frame.height_;
audio_frame.height_ = 0;
}
return *this;
}
AudioFrame::~AudioFrame() {
if (buffer_) {
delete buffer_;
buffer_ = nullptr;
}
size_ = 0;
width_ = 0;
height_ = 0;
}

39
src/frame/audio_frame.h Normal file
View File

@@ -0,0 +1,39 @@
/*
* @Author: DI JUNKUN
* @Date: 2023-11-24
* Copyright (c) 2023 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _AUDIO_FRAME_H_
#define _AUDIO_FRAME_H_
#include <stddef.h>
#include <stdint.h>
class AudioFrame {
public:
AudioFrame();
AudioFrame(size_t size);
AudioFrame(const uint8_t *buffer, size_t size);
AudioFrame(const uint8_t *buffer, size_t size, size_t width, size_t height);
AudioFrame(const AudioFrame &audio_frame);
AudioFrame(AudioFrame &&audio_frame);
AudioFrame &operator=(const AudioFrame &audio_frame);
AudioFrame &operator=(AudioFrame &&audio_frame);
~AudioFrame();
public:
const uint8_t *Buffer() { return buffer_; }
const size_t Size() { return size_; }
uint8_t *GetBuffer() { return buffer_; }
private:
size_t width_ = 0;
size_t height_ = 0;
uint8_t *buffer_ = nullptr;
size_t size_ = 0;
};
#endif

View File

@@ -1,4 +1,4 @@
#include "frame.h"
#include "video_frame.h"
#include <string.h>

View File

@@ -1,8 +1,14 @@
#ifndef _FRAME_H_
#define _FRAME_H_
/*
* @Author: DI JUNKUN
* @Date: 2023-11-24
* Copyright (c) 2023 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _VIDEO_FRAME_H_
#define _VIDEO_FRAME_H_
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
class VideoFrame {
public: