Skip to content

Commit

Permalink
Update GetField API for Mjpeg.h/c
Browse files Browse the repository at this point in the history
Signed-off-by: Adriaan Niess <adriaan.niess@de.bosch.com>
  • Loading branch information
adriaan-niess committed Aug 28, 2024
1 parent d793cb3 commit b78ff98
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 11 deletions.
20 changes: 17 additions & 3 deletions include/avtp/cvf/Mjpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,22 @@ typedef enum Avtp_MjpegField {
AVTP_MJPEG_FIELD_MAX
} Avtp_MjpegField_t;

int Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu);
void Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu);

int Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t* value);
uint64_t Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field);

int Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value);
uint8_t Avtp_Mjpeg_GetTypeSpecific(Avtp_Mjpeg_t* pdu);
uint32_t Avtp_Mjpeg_GetFragmentOffset(Avtp_Mjpeg_t* pdu);
uint8_t Avtp_Mjpeg_GetType(Avtp_Mjpeg_t* pdu);
uint8_t Avtp_Mjpeg_GetQ(Avtp_Mjpeg_t* pdu);
uint8_t Avtp_Mjpeg_GetWidth(Avtp_Mjpeg_t* pdu);
uint8_t Avtp_Mjpeg_GetHeight(Avtp_Mjpeg_t* pdu);

void Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value);

void Avtp_Mjpeg_SetTypeSpecific(Avtp_Mjpeg_t* pdu, uint8_t value);
void Avtp_Mjpeg_SetFragmentOffset(Avtp_Mjpeg_t* pdu, uint32_t value);
void Avtp_Mjpeg_SetType(Avtp_Mjpeg_t* pdu, uint8_t value);
void Avtp_Mjpeg_SetQ(Avtp_Mjpeg_t* pdu, uint8_t value);
void Avtp_Mjpeg_SetWidth(Avtp_Mjpeg_t* pdu, uint8_t value);
void Avtp_Mjpeg_SetHeight(Avtp_Mjpeg_t* pdu, uint8_t value);
81 changes: 73 additions & 8 deletions src/avtp/cvf/Mjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "avtp/Utils.h"
#include "avtp/CommonHeader.h"

#define GET_FIELD(field) \
(Avtp_GetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field))
#define SET_FIELD(field, value) \
(Avtp_SetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field, value))

static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_MJPEG_FIELD_MAX] =
{
[AVTP_MJPEG_FIELD_TYPE_SPECIFIC] = { .quadlet = 0, .offset = 0, .bits = 8 },
Expand All @@ -44,19 +49,79 @@ static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_MJPEG_FIELD_MAX] =
[AVTP_MJPEG_FIELD_HEIGHT] = { .quadlet = 1, .offset = 24, .bits = 8 },
};

int Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu)
void Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu)
{
if (pdu != NULL) {
memset(pdu, 0, sizeof(Avtp_Mjpeg_t));
}
}

uint64_t Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field)
{
return GET_FIELD(field);
}

uint8_t Avtp_Mjpeg_GetTypeSpecific(Avtp_Mjpeg_t* pdu)
{
SET_FIED(AVTP_MJPEG_FIELD_TYPE_SPECIFIC);
}

uint32_t Avtp_Mjpeg_GetFragmentOffset(Avtp_Mjpeg_t* pdu)
{
SET_FIED(AVTP_MJPEG_FIELD_FRAGMENT_OFFSET);
}

uint8_t Avtp_Mjpeg_GetType(Avtp_Mjpeg_t* pdu)
{
SET_FIED(AVTP_MJPEG_FIELD_TYPE);
}

uint8_t Avtp_Mjpeg_GetQ(Avtp_Mjpeg_t* pdu)
{
SET_FIED(AVTP_MJPEG_FIELD_Q);
}

uint8_t Avtp_Mjpeg_GetWidth(Avtp_Mjpeg_t* pdu)
{
SET_FIED(AVTP_MJPEG_FIELD_WIDTH);
}

uint8_t Avtp_Mjpeg_GetHeight(Avtp_Mjpeg_t* pdu)
{
SET_FIED(AVTP_MJPEG_FIELD_HEIGHT);
}

void Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value)
{
SET_FIELD(field, value);
}

void Avtp_Mjpeg_SetTypeSpecific(Avtp_Mjpeg_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_MJPEG_FIELD_TYPE_SPECIFIC, value);
}

void Avtp_Mjpeg_SetFragmentOffset(Avtp_Mjpeg_t* pdu, uint32_t value)
{
SET_FIELD(AVTP_MJPEG_FIELD_FRAGMENT_OFFSET, value);
}

void Avtp_Mjpeg_SetType(Avtp_Mjpeg_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_MJPEG_FIELD_TYPE, value);
}

void Avtp_Mjpeg_SetQ(Avtp_Mjpeg_t* pdu, uint8_t value)
{
if (pdu == NULL) return -EINVAL;
memset(pdu, 0, sizeof(Avtp_Mjpeg_t));
return 0;
SET_FIELD(AVTP_MJPEG_FIELD_Q, value);
}

int Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t* value)
void Avtp_Mjpeg_SetWidth(Avtp_Mjpeg_t* pdu, uint8_t value)
{
return Avtp_GetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field, value);
SET_FIELD(AVTP_MJPEG_FIELD_WIDTH, value);
}

int Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value)
void Avtp_Mjpeg_SetHeight(Avtp_Mjpeg_t* pdu, uint8_t value)
{
return Avtp_SetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field, value);
SET_FIELD(AVTP_MJPEG_FIELD_HEIGHT, value);
}

0 comments on commit b78ff98

Please sign in to comment.