Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(libxmf): expose libvpx,add rust examples with it #55

Merged
merged 55 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
db10af7
WIP
irvingoujAtDevolution Nov 8, 2024
25bc925
WIP: need to work on pts and duration and reference block
irvingoujAtDevolution Nov 11, 2024
181c042
feat[xmf]:expose libvpx,add usage examples with it
irvingoujAtDevolution Nov 13, 2024
49ae7e0
clean up
irvingoujAtDevolution Nov 13, 2024
8aea44f
clean up
irvingoujAtDevolution Nov 13, 2024
47953be
clean up
irvingoujAtDevolution Nov 13, 2024
97bc2fb
clean up
irvingoujAtDevolution Nov 13, 2024
8f367e9
Update rust/cadeau/examples/cut/debug.rs
irvingoujAtDevolution Nov 14, 2024
57d52aa
Update rust/cadeau/examples/cut/main.rs
irvingoujAtDevolution Nov 14, 2024
81fc8b9
review fix c
irvingoujAtDevolution Nov 14, 2024
90a4427
Merge branch 'ARC-251-devolutions-gateway-video-session-shadowing' of…
irvingoujAtDevolution Nov 14, 2024
73b4d35
review fix rust
irvingoujAtDevolution Nov 14, 2024
6025807
review fix:VpxFrame::new
irvingoujAtDevolution Nov 14, 2024
9ee796d
review fix:VpxFrame::new
irvingoujAtDevolution Nov 14, 2024
6ef6afd
review fix:VpxPacket:drop
irvingoujAtDevolution Nov 14, 2024
5358f1c
review fix:VpxImage:Drop
irvingoujAtDevolution Nov 14, 2024
504b5b7
review fix:VpxPacket mut ptr
irvingoujAtDevolution Nov 14, 2024
028093b
review fix: example
irvingoujAtDevolution Nov 14, 2024
8d7df11
review fix: recorder
irvingoujAtDevolution Nov 14, 2024
17a34bb
review fix: vpx definition
irvingoujAtDevolution Nov 14, 2024
5fa7aee
review fix: vpx pub use
irvingoujAtDevolution Nov 14, 2024
5e4cfcd
review fix: vpx life time
irvingoujAtDevolution Nov 14, 2024
b00e604
Update rust/cadeau/src/xmf/vpx/mod.rs
irvingoujAtDevolution Nov 14, 2024
81d6eca
Update libxmf/XmfVpxDecoder.h
irvingoujAtDevolution Nov 14, 2024
f3142cb
review fix:use c_int and c_uint
irvingoujAtDevolution Nov 14, 2024
a404fab
Update rust/xmf-sys/build.rs
irvingoujAtDevolution Nov 14, 2024
8173740
Update rust/xmf-sys/src/vpx.rs
irvingoujAtDevolution Nov 14, 2024
823e9b3
review fix
irvingoujAtDevolution Nov 15, 2024
c7d83e0
Merge branch 'ARC-251-devolutions-gateway-video-session-shadowing' of…
irvingoujAtDevolution Nov 15, 2024
95cec11
Update rust/xmf-sys/src/vpx.rs
irvingoujAtDevolution Nov 15, 2024
a3982f0
compress example file
irvingoujAtDevolution Nov 15, 2024
71d9dc4
Merge branch 'ARC-251-devolutions-gateway-video-session-shadowing' of…
irvingoujAtDevolution Nov 15, 2024
bd8cccf
reset recording.rs
irvingoujAtDevolution Nov 18, 2024
0bcbf7f
review fix, comment
irvingoujAtDevolution Nov 18, 2024
8bb6806
review fix: last error
irvingoujAtDevolution Nov 19, 2024
e448b78
fix comments
irvingoujAtDevolution Nov 19, 2024
1ae878f
fix i32 and u32
irvingoujAtDevolution Nov 19, 2024
62104aa
fix safety errors
irvingoujAtDevolution Nov 19, 2024
562667a
fix unexported function
irvingoujAtDevolution Nov 19, 2024
3c38f9b
review fix
irvingoujAtDevolution Nov 19, 2024
71cf58c
review fix
irvingoujAtDevolution Nov 19, 2024
0705ac1
semantic lifetime and marker
irvingoujAtDevolution Nov 19, 2024
2bf97dc
doc
irvingoujAtDevolution Nov 19, 2024
61dbce1
use & instead of &mut
irvingoujAtDevolution Nov 19, 2024
73b1be4
undo recorder.rs
irvingoujAtDevolution Nov 19, 2024
eff3a88
safety comment
irvingoujAtDevolution Nov 19, 2024
51138b0
remove unused import
irvingoujAtDevolution Nov 19, 2024
37d40a6
remove encoder config
irvingoujAtDevolution Nov 19, 2024
10d289b
update comments
irvingoujAtDevolution Nov 19, 2024
da63c0c
update comments
irvingoujAtDevolution Nov 19, 2024
7c577f3
update comments
irvingoujAtDevolution Nov 19, 2024
8b84a59
update comments
irvingoujAtDevolution Nov 19, 2024
f6fd5a9
update comments
irvingoujAtDevolution Nov 19, 2024
fec1d3e
update rust toolchanin version to use expect attribute
irvingoujAtDevolution Nov 19, 2024
6a4862a
update help
irvingoujAtDevolution Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ package/
output.*
capture_sample*
launchSettings.json
./examples/
10 changes: 10 additions & 0 deletions libxmf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ set(${MODULE_PREFIX}_SOURCES
XmfNamedPipe.c
XmfRecorder.c
XmfMuxer.cpp
XmfVpxDecoder.c
XmfVpxEncoder.c
XmfVpxImage.c
XmfVpxPacket.c
XmfVpxFrame.c
)

set(${MODULE_PREFIX}_HEADERS
Expand All @@ -30,6 +35,11 @@ set(${MODULE_PREFIX}_HEADERS
XmfNamedPipe.h
XmfRecorder.h
XmfMuxer.h
XmfVpxDecoder.h
XmfVpxEncoder.h
XmfVpxImage.h
XmfVpxPacket.h
XmfVpxFrame.h
)

set(${MODULE_PREFIX}_RESOURCES "")
Expand Down
103 changes: 103 additions & 0 deletions libxmf/XmfVpxDecoder.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "XmfVpxDecoder.h"
#include <stdlib.h>
#include <string.h>
#include <vpx/vp8dx.h>
#include <vpx/vpx_decoder.h>
#include "XmfVpxImage.h"

// Internal decoder structure
struct xmf_vpx_decoder
{
vpx_codec_ctx_t codec;
XmfVpxDecoderError lastError;
};

XmfVpXDecoder *XmfVpxDecoder_Create(XmfVpxDecoderConfig cfg)
{

XmfVpXDecoder *decoder = (XmfVpXDecoder *)calloc(1, sizeof(XmfVpXDecoder));
if (!decoder)
{
return NULL;
}

decoder->lastError.code = NO_ERROR;

vpx_codec_dec_cfg_t dec_cfg = {
.threads = cfg.threads,
.w = cfg.w,
.h = cfg.h};

vpx_codec_iface_t *iface = (cfg.codec == VP8) ? vpx_codec_vp8_dx() : vpx_codec_vp9_dx();

vpx_codec_err_t res = vpx_codec_dec_init(&decoder->codec, iface, &dec_cfg, 0);
if (res != VPX_CODEC_OK)
{
free(decoder);
return NULL;
}

return decoder;
}

int XmfVpxDecoder_Decode(XmfVpXDecoder *decoder, const uint8_t *data, unsigned int size)
{
if (!decoder || !data || size == 0)
{
return -1;
}

vpx_codec_err_t res = vpx_codec_decode(&decoder->codec, data, size, NULL, 0);
if (res != VPX_CODEC_OK)
{
decoder->lastError.code = DECODE_ERROR;
decoder->lastError.detail.vpx_error.error_code = res;
return -1;
}

decoder->lastError.code = NO_ERROR;
return 0;
}

XmfVpxImage *XmfVpxDecoder_GetNextFrame(XmfVpXDecoder *decoder)
{
if (!decoder)
{
return NULL;
}

vpx_codec_iter_t itr = NULL;
vpx_image_t *image = vpx_codec_get_frame(&decoder->codec, &itr);
if (!image)
{
decoder->lastError.code = NO_FRAME_AVAILABLE;
return NULL;
}

decoder->lastError.code = NO_ERROR;
XmfVpxImage *result = XmfVpxImage_Create(image);
return result;
}

XmfVpxDecoderError XmfVpxDecoder_GetLastError(XmfVpXDecoder *decoder)
{
XmfVpxDecoderError error = {0};
if (decoder)
{
error = decoder->lastError;
}
else
{
error.code = MEMORY_ERROR;
}
return error;
}

void XmfVpxDecoder_Destroy(XmfVpXDecoder *decoder)
{
if (decoder)
{
vpx_codec_destroy(&decoder->codec);
free(decoder);
}
}
102 changes: 102 additions & 0 deletions libxmf/XmfVpxDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#ifndef XMF_VPXDECODER_H
#define XMF_VPXDECODER_H

#include <stdint.h>
#include "vpx/vpx_codec.h"
#include "xmf/xmf.h"
#include "XmfVpxImage.h"

typedef struct xmf_vpx_decoder XmfVpXDecoder;

typedef enum
{
VP8,
VP9,
} XmfVpxCodecType;

typedef struct xmf_vpx_decoder_config
{
uint32_t threads; /**< Maximum number of threads to use, default 1 */
uint32_t w; /**< Width (set to 0 if unknown) */
uint32_t h; /**< Height (set to 0 if unknown) */
XmfVpxCodecType codec;
} XmfVpxDecoderConfig;

typedef enum xmf_vpx_decoder_error_code
{
NO_ERROR = 0,
MEMORY_ERROR = 1,
INIT_ERROR = 2,
DECODE_ERROR = 3,
NO_FRAME_AVAILABLE = 4,
VPX_ERROR = 5,
} XmfVpxDecoderErrorCode;

/**
* @brief Error information for the decoder.
*
* When the error code is of enum XmfVpxDecoderErrorCode::VPX_ERROR, the union detail.vpx_error.error_code is set to the VPX error code.
*/
typedef struct xmf_vpx_decoder_error
{
XmfVpxDecoderErrorCode code;
union
{
struct
{
vpx_codec_err_t error_code;
} vpx_error;
} detail;
} XmfVpxDecoderError;

#ifdef __cplusplus
extern "C"
{
#endif

/**
* @brief Creates and initializes a VPX decoder.
*
* @param cfg Pointer to the decoder configuration.
* @return Pointer to the decoder instance, or NULL on failure.
*/
XMF_EXPORT XmfVpXDecoder *XmfVpxDecoder_Create(XmfVpxDecoderConfig cfg);

/**
* @brief Decodes compressed data.
*
* @param ctx Pointer to the decoder instance.
* @param data Compressed data buffer.
* @param size Size of the data buffer.
* @return 0 on success, -1 on failure.
*/
XMF_EXPORT int XmfVpxDecoder_Decode(XmfVpXDecoder *ctx, const uint8_t *data, unsigned int size);

/**
* @brief Retrieves the next decoded frame.
*
* @param ctx Pointer to the decoder instance.
* @return Pointer to the decoded image, or NULL if no frame is available.
*/
XMF_EXPORT XmfVpxImage *XmfVpxDecoder_GetNextFrame(XmfVpXDecoder *ctx);

/**
* @brief Retrieves the last error that occurred in the decoder.
*
* @param ctx Pointer to the decoder instance.
* @return The last error information.
*/
XMF_EXPORT XmfVpxDecoderError XmfVpxDecoder_GetLastError(XmfVpXDecoder *ctx);

/**
* @brief Destroys the decoder and frees associated resources.
*
* @param ctx Pointer to the decoder instance.
*/
XMF_EXPORT void XmfVpxDecoder_Destroy(XmfVpXDecoder *ctx);

#ifdef __cplusplus
}
#endif

#endif /* XMF_VPXDECODER_H */
Loading