1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright (C) 2004-2010, Eric Lund
* http://www.mvpmc.org/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* keyframe.c - functions to manage key frame structures. Mostly
* just allocating, freeing, and filling them out.
*/
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <cmyth_local.h>
/*
* cmyth_keyframe_create(void)
*
* Scope: PUBLIC
*
* Description
*
* Create a key frame structure.
*
* Return Value:
*
* Success: A non-NULL cmyth_keyframe_t (this type is a pointer)
*
* Failure: A NULL cmyth_keyframe_t
*/
cmyth_keyframe_t
cmyth_keyframe_create(void)
{
cmyth_keyframe_t ret = ref_alloc(sizeof(*ret));
cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__);
if (!ret) {
cmyth_dbg(CMYTH_DBG_DEBUG, "%s } !\n", __FUNCTION__);
return NULL;
}
ret->keyframe_number = 0;
ret->keyframe_pos = 0;
cmyth_dbg(CMYTH_DBG_DEBUG, "%s }\n", __FUNCTION__);
return ret;
}
/*
* cmyth_keyframe_fill(cmyth_keyframe_t kf,
* unsigned long keynum,
* unsigned long long pos)
*
* Scope: PUBLIC
*
* Description
*
* Fill out the contents of the recorder number structure 'rn' using
* the values 'keynum' and 'pos'.
*
* Return Value:
*
* Success: 0
*
* Failure: -(ERRNO)
*/
cmyth_keyframe_t
cmyth_keyframe_fill(unsigned long keynum, unsigned long long pos)
{
cmyth_keyframe_t ret = cmyth_keyframe_create();
if (!ret) {
return NULL;
}
ret->keyframe_number = keynum;
ret->keyframe_pos = pos;
return ret;
}
/*
* cmyth_keyframe_string(cmyth_keyframe_t kf)
*
* Scope: PUBLIC
*
* Description
*
* Compose a MythTV protocol string from a keyframe structure and
* return a pointer to a malloc'ed buffer containing the string.
*
* Return Value:
*
* Success: A non-NULL malloc'ed character buffer pointer.
*
* Failure: NULL
*/
char *
cmyth_keyframe_string(cmyth_keyframe_t kf)
{
unsigned len = sizeof("[]:[]");
char key[32];
char pos[32];
char *ret;
if (!kf) {
return NULL;
}
sprintf(pos, "%lld", kf->keyframe_pos);
len += strlen(pos);
sprintf(key, "%ld", kf->keyframe_number);
len += strlen(key);
ret = malloc(len * sizeof(char));
if (!ret) {
return NULL;
}
strcpy(ret, key);
strcat(ret, "[]:[]");
strcat(ret, pos);
return ret;
}
|