blob: a670a11727e9105c1fdc4125943cfb3f178d1cfc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*
* Copyright (c) 2018 Vasile Vilvoiu (YO7JBP) <vasi.vilvoiu@gmail.com>
*
* libsstv is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#include "sstv.h"
#include "libsstv.h"
/*
* Encoder context
*/
typedef struct {
/* common encoder stuff */
sstv_mode_t mode;
} sstv_encoder_context_t;
/* default encoder contexts, for when no allocation/deallocation routines are provided */
static sstv_encoder_context_t default_encoder_context[SSTV_DEFAULT_ENCODER_CONTEXT_COUNT];
static uint64_t default_encoder_context_usage = 0x0;
sstv_error_t
sstv_create_encoder(sstv_mode_t mode, uint8_t *image, size_t sample_rate, void **out_ctx)
{
sstv_encoder_context_t *ctx = NULL;
/* check input */
if (!out_ctx) {
return SSTV_BAD_PARAMETER;
}
/* create context */
if (sstv_malloc_user) {
/* user allocator */
ctx = (sstv_encoder_context_t *) sstv_malloc_user(sizeof(sstv_encoder_context_t));
if (!ctx) {
return SSTV_BAD_USER_ALLOC;
}
} else {
size_t i;
/* use default contexts */
for (i = 0; i < SSTV_DEFAULT_ENCODER_CONTEXT_COUNT; i++) {
if ((default_encoder_context_usage & (0x1 << i)) == 0) {
default_encoder_context_usage |= (0x1 << i);
ctx = &default_encoder_context[i];
break;
}
}
}
if (!ctx) {
return SSTV_INTERNAL_ERROR;
}
/* initialize context */
ctx->mode = mode;
/* set output */
*out_ctx = ctx;
/* all ok */
return SSTV_OK;
}
sstv_error_t
sstv_delete_encoder(void *ctx)
{
size_t i;
/* check default contexts */
for (i = 0; i < SSTV_DEFAULT_ENCODER_CONTEXT_COUNT; i++) {
if (ctx == default_encoder_context+i) {
default_encoder_context_usage &= ~(0x1 << i);
ctx = NULL;
break;
}
}
/* deallocate context */
if (ctx) {
if (!sstv_free_user) {
return SSTV_BAD_USER_DEALLOC;
}
sstv_free_user(ctx);
}
/* all ok */
return SSTV_OK;
}
sstv_error_t
sstv_encode(void *ctx, uint8_t *buffer, size_t buffer_size)
{
}
|