Statistics
| Branch: | Revision:

chunker-player / event_http / chunk_receiver.c @ 59c85ad1

History | View | Annotate | Download (1.23 KB)

1
/**
2
 * @file chunk_receiver.c
3
 *
4
 * Chunk Receiver "object".
5
 *
6
 * No threads, thus it is based on callbacks and timer events.
7
 *
8
 * Napa-Wine project 2009-2010
9
 * @author: Giuseppe Tropea <giuseppe.tropea@lightcomm.it>
10
 */
11

    
12
#include "chunk_external_interface.h"
13

    
14
int ulChunkReceiverSetup(const char *address, unsigned short port) {
15
  if(ulEventHttpServerSetup(address, port, &ulPushChunkToChunkBuffer_cb)) {
16
    return UL_RETURN_FAIL;
17
  }
18
  else {
19
    debug("Chunk receiver setup OK");
20
    return UL_RETURN_OK;
21
  }
22
}
23

    
24
int ulPushChunkToChunkBuffer_cb(const uint8_t *encoded_chunk, int encoded_chunk_len) {
25
  Chunk decoded_chunk;
26
  debug("Processing incoming chunk of %d encoded bytes", encoded_chunk_len);
27
//print_block(encoded_chunk, encoded_chunk_len);
28
  int size = decodeChunk(&decoded_chunk, encoded_chunk, encoded_chunk_len);
29
  debug("Just decoded chunk %d", decoded_chunk.id);
30
  //push new chunk into chunk buffer
31
  chbAddChunk(chunkbuffer, &decoded_chunk);
32
  debug("Just pushed chunk %d of %d bytes into chunkbuf", decoded_chunk.id, size);
33
  return UL_RETURN_OK;
34
}
35

    
36
void print_block(const uint8_t *b, int size) {
37
int i=0;
38
printf("BEGIN OF %d BYTES---\n", size);
39
for(i=0; i<size; i++) {
40
printf("%d ", *(b+i));
41
}
42
printf("END OF %d BYTES---\n", size);
43
}