mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-18 02:55:46 +00:00
using uint8_t
This commit is contained in:
parent
f19ab11f76
commit
9e1bf2fdea
@ -142,7 +142,7 @@ void rawsink_destroy(struct rawsink_t *rawsink) {
|
||||
|
||||
void rawsink_put(
|
||||
struct rawsink_t *rawsink,
|
||||
const unsigned char *data, size_t size,
|
||||
const uint8_t *data, size_t size,
|
||||
unsigned format, unsigned width, unsigned height,
|
||||
long double grab_ts) {
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
@ -44,12 +45,12 @@
|
||||
|
||||
|
||||
struct rawsink_shared_t {
|
||||
unsigned format;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
long double grab_ts;
|
||||
size_t size;
|
||||
unsigned char data[RAWSINK_MAX_DATA];
|
||||
unsigned format;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
long double grab_ts;
|
||||
size_t size;
|
||||
uint8_t data[RAWSINK_MAX_DATA];
|
||||
};
|
||||
|
||||
struct rawsink_t {
|
||||
@ -75,7 +76,7 @@ void rawsink_destroy(struct rawsink_t *rawsink);
|
||||
|
||||
void rawsink_put(
|
||||
struct rawsink_t *rawsink,
|
||||
const unsigned char *data, size_t size,
|
||||
const uint8_t *data, size_t size,
|
||||
unsigned format, unsigned witdh, unsigned height,
|
||||
long double grab_ts);
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ const unsigned BLANK_JPEG_WIDTH = 640;
|
||||
const unsigned BLANK_JPEG_HEIGHT = 480;
|
||||
|
||||
const size_t BLANK_JPEG_DATA_SIZE = 13845;
|
||||
const unsigned char BLANK_JPEG_DATA[] = {
|
||||
const uint8_t BLANK_JPEG_DATA[] = {
|
||||
0xFF, 0xD8, 0xFF, 0xE1, 0x09, 0x50, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6E, 0x73, 0x2E, 0x61, 0x64, 0x6F, 0x62,
|
||||
0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x78, 0x61, 0x70, 0x2F, 0x31, 0x2E, 0x30, 0x2F, 0x00, 0x3C, 0x3F, 0x78, 0x70, 0x61,
|
||||
0x63, 0x6B, 0x65, 0x74, 0x20, 0x62, 0x65, 0x67, 0x69, 0x6E, 0x3D, 0x22, 0xEF, 0xBB, 0xBF, 0x22, 0x20, 0x69, 0x64, 0x3D,
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
@ -29,4 +31,4 @@ extern const unsigned BLANK_JPEG_WIDTH;
|
||||
extern const unsigned BLANK_JPEG_HEIGHT;
|
||||
|
||||
extern const size_t BLANK_JPEG_DATA_SIZE;
|
||||
extern const unsigned char BLANK_JPEG_DATA[];
|
||||
extern const uint8_t BLANK_JPEG_DATA[];
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
@ -70,13 +71,13 @@
|
||||
|
||||
|
||||
struct hw_buffer_t {
|
||||
unsigned char *data;
|
||||
size_t used;
|
||||
size_t allocated;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
unsigned format;
|
||||
long double grab_ts;
|
||||
uint8_t *data;
|
||||
size_t used;
|
||||
size_t allocated;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
unsigned format;
|
||||
long double grab_ts;
|
||||
|
||||
struct v4l2_buffer buf_info;
|
||||
|
||||
|
||||
@ -38,19 +38,19 @@ struct _jpeg_dest_manager_t {
|
||||
static void _jpeg_set_picture(j_compress_ptr jpeg, struct frame_t *frame);
|
||||
|
||||
static void _jpeg_write_scanlines_yuyv(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
static void _jpeg_write_scanlines_uyvy(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
static void _jpeg_write_scanlines_rgb565(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
static void _jpeg_write_scanlines_rgb24(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height);
|
||||
|
||||
static void _jpeg_init_destination(j_compress_ptr jpeg);
|
||||
@ -123,17 +123,17 @@ static void _jpeg_set_picture(j_compress_ptr jpeg, struct frame_t *frame) {
|
||||
#define NORM_COMPONENT(_x) (((_x) > 255) ? 255 : (((_x) < 0) ? 0 : (_x)))
|
||||
|
||||
static void _jpeg_write_scanlines_yuyv(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height) {
|
||||
|
||||
unsigned char *line_buffer;
|
||||
uint8_t *line_buffer;
|
||||
JSAMPROW scanlines[1];
|
||||
unsigned z = 0;
|
||||
|
||||
A_CALLOC(line_buffer, width * 3);
|
||||
|
||||
while (jpeg->next_scanline < height) {
|
||||
unsigned char *ptr = line_buffer;
|
||||
uint8_t *ptr = line_buffer;
|
||||
|
||||
for (unsigned x = 0; x < width; ++x) {
|
||||
int y = (!z ? data[0] << 8 : data[2] << 8);
|
||||
@ -162,17 +162,17 @@ static void _jpeg_write_scanlines_yuyv(
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_uyvy(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height) {
|
||||
|
||||
unsigned char *line_buffer;
|
||||
uint8_t *line_buffer;
|
||||
JSAMPROW scanlines[1];
|
||||
unsigned z = 0;
|
||||
|
||||
A_CALLOC(line_buffer, width * 3);
|
||||
|
||||
while (jpeg->next_scanline < height) {
|
||||
unsigned char *ptr = line_buffer;
|
||||
uint8_t *ptr = line_buffer;
|
||||
|
||||
for(unsigned x = 0; x < width; ++x) {
|
||||
int y = (!z ? data[1] << 8 : data[3] << 8);
|
||||
@ -206,22 +206,22 @@ static void _jpeg_write_scanlines_uyvy(
|
||||
#undef YUV_R
|
||||
|
||||
static void _jpeg_write_scanlines_rgb565(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height) {
|
||||
|
||||
unsigned char *line_buffer;
|
||||
uint8_t *line_buffer;
|
||||
JSAMPROW scanlines[1];
|
||||
|
||||
A_CALLOC(line_buffer, width * 3);
|
||||
|
||||
while (jpeg->next_scanline < height) {
|
||||
unsigned char *ptr = line_buffer;
|
||||
uint8_t *ptr = line_buffer;
|
||||
|
||||
for(unsigned x = 0; x < width; ++x) {
|
||||
unsigned int two_byte = (data[1] << 8) + data[0];
|
||||
|
||||
*(ptr++) = data[1] & 248; // Red
|
||||
*(ptr++) = (unsigned char)((two_byte & 2016) >> 3); // Green
|
||||
*(ptr++) = (uint8_t)((two_byte & 2016) >> 3); // Green
|
||||
*(ptr++) = (data[0] & 31) * 8; // Blue
|
||||
|
||||
data += 2;
|
||||
@ -235,13 +235,13 @@ static void _jpeg_write_scanlines_rgb565(
|
||||
}
|
||||
|
||||
static void _jpeg_write_scanlines_rgb24(
|
||||
struct jpeg_compress_struct *jpeg, const unsigned char *data,
|
||||
struct jpeg_compress_struct *jpeg, const uint8_t *data,
|
||||
unsigned width, unsigned height) {
|
||||
|
||||
JSAMPROW scanlines[1];
|
||||
|
||||
while (jpeg->next_scanline < height) {
|
||||
scanlines[0] = (unsigned char *)(data + jpeg->next_scanline * width * 3);
|
||||
scanlines[0] = (uint8_t *)(data + jpeg->next_scanline * width * 3);
|
||||
jpeg_write_scanlines(jpeg, scanlines, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <jpeglib.h>
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
|
||||
void _copy_plus_huffman(const struct hw_buffer_t *src, struct frame_t *dest);
|
||||
static bool _is_huffman(const unsigned char *data);
|
||||
static bool _is_huffman(const uint8_t *data);
|
||||
|
||||
|
||||
int hw_encoder_prepare(struct device_t *dev, unsigned quality) {
|
||||
@ -58,8 +58,8 @@ void hw_encoder_compress_buffer(struct hw_buffer_t *hw, struct frame_t *frame) {
|
||||
|
||||
void _copy_plus_huffman(const struct hw_buffer_t *src, struct frame_t *dest) {
|
||||
if (!_is_huffman(src->data)) {
|
||||
const unsigned char *src_ptr = src->data;
|
||||
const unsigned char *src_end = src->data + src->used;
|
||||
const uint8_t *src_ptr = src->data;
|
||||
const uint8_t *src_end = src->data + src->used;
|
||||
size_t paste;
|
||||
|
||||
while ((((src_ptr[0] << 8) | src_ptr[1]) != 0xFFC0) && (src_ptr < src_end)) {
|
||||
@ -79,14 +79,14 @@ void _copy_plus_huffman(const struct hw_buffer_t *src, struct frame_t *dest) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool _is_huffman(const unsigned char *data) {
|
||||
static bool _is_huffman(const uint8_t *data) {
|
||||
unsigned count = 0;
|
||||
|
||||
while (((data[0] << 8) | data[1]) != 0xFFDA) {
|
||||
while ((((uint16_t)data[0] << 8) | data[1]) != 0xFFDA) {
|
||||
if (count++ > 2048) {
|
||||
return false;
|
||||
}
|
||||
if (((data[0] << 8) | data[1]) == 0xFFC4) {
|
||||
if ((((uint16_t)data[0] << 8) | data[1]) == 0xFFC4) {
|
||||
return true;
|
||||
}
|
||||
data += 1;
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@ -27,7 +27,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
static const unsigned char HUFFMAN_TABLE[] = {
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
static const uint8_t HUFFMAN_TABLE[] = {
|
||||
0xFF, 0xC4, 0x01, 0xA2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01,
|
||||
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
|
||||
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x01, 0x00, 0x03,
|
||||
|
||||
@ -48,13 +48,13 @@ void frame_realloc_data(struct frame_t *frame, size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
void frame_set_data(struct frame_t *frame, const unsigned char *data, size_t size) {
|
||||
void frame_set_data(struct frame_t *frame, const uint8_t *data, size_t size) {
|
||||
frame_realloc_data(frame, size);
|
||||
memcpy(frame->data, data, size);
|
||||
frame->used = size;
|
||||
}
|
||||
|
||||
void frame_append_data(struct frame_t *frame, const unsigned char *data, size_t size) {
|
||||
void frame_append_data(struct frame_t *frame, const uint8_t *data, size_t size) {
|
||||
size_t new_used = frame->used + size;
|
||||
|
||||
frame_realloc_data(frame, new_used);
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -33,15 +34,15 @@
|
||||
|
||||
|
||||
struct frame_t {
|
||||
const char *role;
|
||||
unsigned char *data;
|
||||
size_t used;
|
||||
size_t allocated;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
long double grab_ts;
|
||||
long double encode_begin_ts;
|
||||
long double encode_end_ts;
|
||||
const char *role;
|
||||
uint8_t *data;
|
||||
size_t used;
|
||||
size_t allocated;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
long double grab_ts;
|
||||
long double encode_begin_ts;
|
||||
long double encode_end_ts;
|
||||
};
|
||||
|
||||
|
||||
@ -49,8 +50,8 @@ struct frame_t *frame_init(const char *role);
|
||||
void frame_destroy(struct frame_t *frame);
|
||||
|
||||
void frame_realloc_data(struct frame_t *frame, size_t size);
|
||||
void frame_set_data(struct frame_t *frame, const unsigned char *data, size_t size);
|
||||
void frame_append_data(struct frame_t *frame, const unsigned char *data, size_t size);
|
||||
void frame_set_data(struct frame_t *frame, const uint8_t *data, size_t size);
|
||||
void frame_append_data(struct frame_t *frame, const uint8_t *data, size_t size);
|
||||
|
||||
void frame_copy(const struct frame_t *src, struct frame_t *dest);
|
||||
bool frame_compare(const struct frame_t *a, const struct frame_t *b);
|
||||
|
||||
@ -37,7 +37,7 @@ static const char _ENCODING_TABLE[] = {
|
||||
static const unsigned _MOD_TABLE[] = {0, 2, 1};
|
||||
|
||||
|
||||
char *base64_encode(const unsigned char *str) {
|
||||
char *base64_encode(const uint8_t *str) {
|
||||
size_t str_len = strlen((const char *)str);
|
||||
size_t encoded_size = 4 * ((str_len + 2) / 3) + 1; // +1 for '\0'
|
||||
char *encoded;
|
||||
@ -45,9 +45,9 @@ char *base64_encode(const unsigned char *str) {
|
||||
A_CALLOC(encoded, encoded_size);
|
||||
|
||||
for (unsigned str_index = 0, encoded_index = 0; str_index < str_len;) {
|
||||
unsigned octet_a = (str_index < str_len ? (unsigned char)str[str_index++] : 0);
|
||||
unsigned octet_b = (str_index < str_len ? (unsigned char)str[str_index++] : 0);
|
||||
unsigned octet_c = (str_index < str_len ? (unsigned char)str[str_index++] : 0);
|
||||
unsigned octet_a = (str_index < str_len ? (uint8_t)str[str_index++] : 0);
|
||||
unsigned octet_b = (str_index < str_len ? (uint8_t)str[str_index++] : 0);
|
||||
unsigned octet_c = (str_index < str_len ? (uint8_t)str[str_index++] : 0);
|
||||
|
||||
unsigned triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
|
||||
|
||||
|
||||
@ -23,9 +23,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../common/tools.h"
|
||||
|
||||
|
||||
char *base64_encode(const unsigned char *str);
|
||||
char *base64_encode(const uint8_t *str);
|
||||
|
||||
@ -157,7 +157,7 @@ int http_server_listen(struct http_server_t *server) {
|
||||
|
||||
A_CALLOC(raw_token, strlen(server->user) + strlen(server->passwd) + 2);
|
||||
sprintf(raw_token, "%s:%s", server->user, server->passwd);
|
||||
encoded_token = base64_encode((unsigned char *)raw_token);
|
||||
encoded_token = base64_encode((uint8_t *)raw_token);
|
||||
free(raw_token);
|
||||
|
||||
A_CALLOC(RUN(auth_token), strlen(encoded_token) + 16);
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdatomic.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -85,7 +85,7 @@ def main() -> None:
|
||||
text += f"const unsigned {name}_JPEG_WIDTH = {width};\n"
|
||||
text += f"const unsigned {name}_JPEG_HEIGHT = {height};\n\n"
|
||||
text += f"const size_t {name}_JPEG_DATA_SIZE = {len(jpeg_data)};\n"
|
||||
text += f"const unsigned char {name}_JPEG_DATA[] = {jpeg_data_text};\n"
|
||||
text += f"const uint8_t {name}_JPEG_DATA[] = {jpeg_data_text};\n"
|
||||
|
||||
with open(c_path, "w") as c_file:
|
||||
c_file.write(text)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user