Statistics
| Branch: | Revision:

chunker-player / chunker_streamer / chunker_metadata.c @ e11386c0

History | View | Annotate | Download (3.42 KB)

1
// chunkbuffer.c
2
// Author 
3
// Giuseppe Tropea
4
//
5
// Use the file compile to compile the program to build (assuming libavformat and libavcodec are 
6
// correctly installed your system).
7
//
8
// Run using
9
//
10
// ingestion myvideofile.mpg
11

    
12

    
13
#include "chunker_metadata.h"
14

    
15

    
16
/* Read config file for chunk strategy [numframes:num|size:num] and create a new chunk_buffer object
17
        numframes:num        fill each chunk with the same number of frame
18
        size:num        fill each chunk with the size of bytes no bigger than num
19
*/
20
struct chunker_metadata *chunkerInit() {
21
        ChunkerMetadata *cmeta=NULL;
22
        cfg_opt_t opts[] =
23
        {
24
                CFG_STR("strategyType", "frames", CFGF_NONE), //"frames" or "size"
25
                CFG_INT("audioFramesPerChunk", 1, CFGF_NONE),
26
                CFG_INT("videoFramesPerChunk", 1, CFGF_NONE),
27
                CFG_INT("targetChunkSize", 1024, CFGF_NONE),
28
                CFG_STR("chunkID", "sequence", CFGF_NONE), //"sequence" or "starttime" or "monotonic"
29
                CFG_STR("outsideWorldUrl", "http://localhost:5557/externalplayer", CFGF_NONE),
30
                CFG_END()
31
        };
32
        cfg_t *cfg;
33

    
34
        fprintf(stderr, "CONFIG: Calling chunkerInit...\n");
35
        cmeta = (ChunkerMetadata *)malloc(sizeof(ChunkerMetadata));
36
        if(cmeta == NULL) {
37
                fprintf(stdout, "CONFIG: Error in memory for cmeta. Exiting.\n");
38
                exit(-1);
39
        }
40

    
41
        cfg = cfg_init(opts, CFGF_NONE);
42
        if(cfg_parse(cfg, "chunker.conf") == CFG_PARSE_ERROR) {
43
                fprintf(stdout, "CONFIG: Error in parsing config file chunker.conf. Exiting.\n");
44
                exit(-1);
45
        }
46

    
47
        if(!(strcmp(cfg_getstr(cfg, "strategyType"), "frames"))) {
48
                // a fixed number of frames inside every chunk
49
                cmeta->strategy = 0;
50
                cmeta->framesPerChunk[0] = cfg_getint(cfg, "audioFramesPerChunk");
51
                cmeta->framesPerChunk[1] = cfg_getint(cfg, "videoFramesPerChunk");
52
                fprintf(stdout, "CONFIG: Will pack %d AUDIO FRAMES or %d VIDEO FRAMES in each chunk\n", cmeta->framesPerChunk[0], cmeta->framesPerChunk[1]);
53
        }
54
        else if(!(strcmp(cfg_getstr(cfg, "strategyType"), "size"))) {
55
                // each chunk of approx same size of bytes
56
                cmeta->strategy = 1;
57
                cmeta->targetChunkSize = cfg_getint(cfg, "targetChunkSize");
58
                fprintf(stdout, "CONFIG: Will pack %d BYTES in each chunk\n", cmeta->targetChunkSize);
59
        }
60
        else {
61
                fprintf(stdout, "CONFIG: Unknown strategyType in config file chunker.conf. Exiting.\n");
62
                exit(-1);
63
        }
64

    
65
        if(!(strcmp(cfg_getstr(cfg, "chunkID"), "sequence"))) {
66
                // the chunkID is an increasing sequence of integers
67
                cmeta->cid = 0;
68
                fprintf(stdout, "CONFIG: Will give increasing SEQUENCE of integers as chunk IDs\n");
69
        }
70
        else if(!(strcmp(cfg_getstr(cfg, "chunkID"), "starttime"))) {
71
                // the chunkID is the chunk start time
72
                cmeta->cid = 1;
73
                fprintf(stdout, "CONFIG: Will give TIMESTAMP of start time as chunk IDs\n");
74
        }
75
        else if(!(strcmp(cfg_getstr(cfg, "chunkID"), "monotonic"))) {
76
                // the chunkID is always increasing also over different runs
77
                //because it's based on the gettimeofday()
78
                cmeta->cid = 2;
79
                fprintf(stdout, "CONFIG: Will give MONOTONIC INCREASING time of day as chunk IDs\n");
80
                struct timeval tv;
81
                uint64_t start_time;
82
                gettimeofday(&tv, NULL);
83
                start_time = tv.tv_usec + tv.tv_sec * 1000000ULL; //microseconds
84
                start_time /= 1000ULL; //milliseconds
85
                cmeta->base_chunkid_sequence_offset = start_time % INT_MAX; //TODO: verify 32/64 bit;
86
        }
87
        else {
88
                fprintf(stdout, "CONFIG: Unknown chunkID in config file chunker.conf. Exiting.\n");
89
                exit(-1);
90
        }
91

    
92
        strcpy(cmeta->outside_world_url, cfg_getstr(cfg, "outsideWorldUrl"));
93
        fprintf(stdout, "CONFIG: Chunk destination is %s\n", cmeta->outside_world_url);
94
        cfg_free(cfg);
95

    
96
        return cmeta;
97
}