Statistics
| Branch: | Revision:

chunker-player / chunk_pusher.c @ 64144d8f

History | View | Annotate | Download (2.31 KB)

1
#include <stdlib.h>
2
#include <string.h>
3

    
4
#include "external_chunk_transcoding.h"
5
#include "chunker_streamer.h"
6

    
7
//#define DEBUG_PUSHER
8

    
9

    
10
int pushChunkHttp(ExternalChunk *echunk, char *url);
11

    
12
extern ChunkerMetadata *cmeta;
13

    
14

    
15
int pushChunkHttp(ExternalChunk *echunk, char *url) {
16
        Chunk gchunk;
17
        void *grapes_chunk_attributes_block = NULL;
18
        int ts1e3 = 0.0;
19
        int tus3e1 = 0.0;
20
        int ret = STREAMER_FAIL_RETURN;
21
        //we need to pack 5 int32s + 2 timeval structs + 1 double
22
        static size_t ExternalChunk_header_size = 5*CHUNK_TRANSCODING_INT_SIZE + 2*CHUNK_TRANSCODING_INT_SIZE + 2*CHUNK_TRANSCODING_INT_SIZE + 1*CHUNK_TRANSCODING_INT_SIZE*2;
23
        
24
        //update the chunk len here because here we know the external chunk header size
25
        echunk->len = echunk->payload_len + ExternalChunk_header_size;
26

    
27
        /* first pack the chunk info that we get from the streamer into an "attributes" block of a regular GRAPES chunk */
28
        if(        (grapes_chunk_attributes_block = packExternalChunkToAttributes(echunk, ExternalChunk_header_size)) != NULL ) {
29
                /* then fill-up a proper GRAPES chunk */
30
                gchunk.size = echunk->payload_len;
31
                /* convert external_chunk start_time in milliseconds and put it in grapes chunk */
32
                ts1e3 = (int)(echunk->start_time.tv_sec*1e3);
33
                //tus3e1 = (int)(echunk->start_time.tv_usec/1e3); ALREADY IN MILLI SECONDS
34
                gchunk.timestamp = ts1e3+(int)(echunk->start_time.tv_usec);
35
#ifdef DEBUG_PUSHER
36
                        fprintf(stderr, "PUSHER: start sec %d usec %d timestamp %ld\n", ts1e3, (int)(echunk->start_time.tv_usec), gchunk.timestamp);
37
#endif
38

    
39
                //decide how to create the chunk ID
40
                if(cmeta->cid == 0) {
41
                        gchunk.id = echunk->seq;
42
#ifdef DEBUG_PUSHER
43
                        fprintf(stderr, "PUSHER: packaged SEQ chunkID %d\n", gchunk.id);
44
#endif
45
                }
46
                else if(cmeta->cid == 1) {
47
                        gchunk.id = gchunk.timestamp; //its ID is its start time
48
#ifdef DEBUG_PUSHER
49
                        fprintf(stderr, "PUSHER: packaged TS chunkID %d\n", gchunk.id);
50
#endif
51
                }
52
                gchunk.attributes = grapes_chunk_attributes_block;
53
                gchunk.attributes_size = ExternalChunk_header_size;
54
                gchunk.data = echunk->data;
55

    
56
#ifdef NHIO
57
                write_chunk(&gchunk);
58
#else
59
                /* 20 bytes are needed to put the chunk header info on the wire + attributes size + payload */
60
                ret = sendViaCurl(gchunk, GRAPES_ENCODED_CHUNK_HEADER_SIZE + gchunk.attributes_size + gchunk.size, url);
61
#endif
62

    
63
                free(grapes_chunk_attributes_block);
64
                return ret;
65
        }
66
        return ret;
67
}