Statistics
| Branch: | Revision:

chunker-player / chunker_metadata.c @ 1e69ae95

History | View | Annotate | Download (1.6 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
void chunker_trim(char *s) {
17
        // Trim spaces and tabs from beginning:
18
        int i=0,j;
19
        while((s[i]==' ')||(s[i]=='\t')) {
20
                i++;
21
        }
22
        if(i>0) {
23
                for(j=0;j<strlen(s);j++) {
24
                        s[j]=s[j+i];
25
                }
26
                s[j]='\0';
27
        }
28

    
29
        // Trim spaces and tabs from end:
30
        i=strlen(s)-1;
31
        while((s[i]==' ')||(s[i]=='\t') || s[i]=='\n') {
32
                i--;
33
        }
34
        if(i<(strlen(s)-1)) {
35
                s[i+1]='\0';
36
        }
37
}
38

    
39
/* Read config file for chunk strategy [numframes:num|size:num] and create a new chunk_buffer object
40
        numframes:num        fill each chunk with the same number of frame
41
        size:num        fill each chunk with the size of bytes no bigger than num
42
*/
43
struct chunker_metadata *chunkerInit(const char *config) {
44
        int isstrategy;
45
        char str[1000];
46
        char *p;
47
        printf("Calling chunkerInit...\n");
48
        FILE *fp = fopen(config,"r");
49
        ChunkerMetadata *cmeta = (ChunkerMetadata *)malloc(sizeof(ChunkerMetadata));
50
        cmeta->echunk = NULL;
51
        cmeta->size = 0;
52
        cmeta->val_strategy = 0;
53
        while(fgets(str,100,fp)!=NULL) {
54
                chunker_trim(str);
55
                if(str[0]=='#')
56
                        continue;
57
                if(!strcmp(str,"[strategy]")) {
58
                        isstrategy=1;
59
                        continue;
60
                }
61
                if(isstrategy==1) {
62
                        p = strtok(str,":");
63
                        chunker_trim(p);
64
                        if(!(strcmp(p,"numframes")))
65
                                cmeta->strategy=0;
66
                        if(!(strcmp(p,"size")))
67
                                cmeta->strategy=1;
68
                        p = strtok(NULL,":");
69
                        sscanf(p,"%d",&cmeta->val_strategy);
70
                        isstrategy=0;
71
                }
72
        }
73
        fclose(fp);
74
        printf("done!\n");
75
        return cmeta;
76
}
77