Statistics
| Branch: | Revision:

chunker-player / chunk_pusher.c @ bd209760

History | View | Annotate | Download (1.89 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
        static size_t attr_size = 0;
19
        int ts1e3 = 0.0;
20
        int tus3e1 = 0.0;
21
        int ret = STREAMER_FAIL_RETURN;
22
        
23
        attr_size = 5*sizeof(int32_t) + 2*sizeof(time_t) + 2*sizeof(suseconds_t) + 1*sizeof(double);
24

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

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

    
54
#ifdef NHIO
55
                        write_chunk(&gchunk);
56
#else
57
                        ret = sendViaCurl(gchunk, attr_size, echunk, url);
58
#endif
59

    
60
                free(grapes_chunk_attributes_block);
61
                return ret;
62
        }
63
        return ret;
64
}