When decoding, don't require packets in the input to be aligned to the packet size

master
Philip Heron 2023-04-14 14:57:41 +01:00
rodzic 83cb0e139b
commit f0248cfd62
2 zmienionych plików z 24 dodań i 3 usunięć

2
README
Wyświetl plik

@ -13,7 +13,7 @@ $ ssdv -e -c TEST01 -i ID input.jpeg output.bin
This encodes the 'input.jpeg' image file into SSDV packets stored in the 'output.bin' file. TEST01 (the callsign, an alphanumeric string up to 6 characters) and ID (a number from 0-255) are encoded into the header of each packet. The ID should be changed for each new image transmitted to allow the decoder to identify when a new image begins.
The output file contains a series of SSDV packets, each packet always being 256 bytes in length. Additional data may be transmitted between each packet, the decoder will ignore this.
The output file contains a series of fixed-length SSDV packets (default 256 bytes). Additional data may be transmitted between each packet, the decoder will ignore this.
DECODING

25
main.c
Wyświetl plik

@ -63,6 +63,7 @@ int main(int argc, char *argv[])
int8_t quality = 4;
int pkt_length = SSDV_PKT_SIZE;
ssdv_t ssdv;
int skipped;
uint8_t pkt[SSDV_PKT_SIZE], b[128], *jpeg;
size_t jpeg_length;
@ -141,18 +142,38 @@ int main(int argc, char *argv[])
ssdv_dec_set_buffer(&ssdv, jpeg, jpeg_length);
i = 0;
while(fread(pkt, 1, pkt_length, fin) > 0)
while(fread(pkt, pkt_length, 1, fin) > 0)
{
/* Drop % of packets */
if(droptest && (rand() / (RAND_MAX / 100) < droptest)) continue;
/* Test the packet is valid */
if(ssdv_dec_is_packet(pkt, pkt_length, &errors) != 0) continue;
skipped = 0;
while((c = ssdv_dec_is_packet(pkt, pkt_length, &errors)) != 0)
{
/* Read 1 byte at a time until a new packet is found */
memmove(&pkt[0], &pkt[1], pkt_length - 1);
if(fread(&pkt[pkt_length - 1], 1, 1, fin) <= 0)
{
break;
}
skipped++;
}
/* No valid packet was found before EOF */
if(c != 0) break;
if(verbose)
{
ssdv_packet_info_t p;
if(skipped > 0)
{
fprintf(stderr, "Skipped %d bytes.\n", skipped);
}
ssdv_dec_header(&p, pkt);
fprintf(stderr, "Decoded image packet. Callsign: %s, Image ID: %d, Resolution: %dx%d, Packet ID: %d (%d errors corrected)\n"
">> Type: %d, Quality: %d, EOI: %d, MCU Mode: %d, MCU Offset: %d, MCU ID: %d/%d\n",