Mercurial > libavcore.hg
comparison parseutils.c @ 3:af138a6c3924 libavcore
Remove reference to the "frame" term in variable names. Simpler and
more consistent with the function names.
author | stefano |
---|---|
date | Mon, 26 Jul 2010 23:12:41 +0000 |
parents | b7595fe2d4a4 |
children | a821459410ee |
comparison
equal
deleted
inserted
replaced
2:b7595fe2d4a4 | 3:af138a6c3924 |
---|---|
25 #include "libavutil/avutil.h" | 25 #include "libavutil/avutil.h" |
26 | 26 |
27 typedef struct { | 27 typedef struct { |
28 const char *abbr; | 28 const char *abbr; |
29 int width, height; | 29 int width, height; |
30 } VideoFrameSizeAbbr; | 30 } VideoSizeAbbr; |
31 | 31 |
32 typedef struct { | 32 typedef struct { |
33 const char *abbr; | 33 const char *abbr; |
34 int rate_num, rate_den; | 34 int rate_num, rate_den; |
35 } VideoFrameRateAbbr; | 35 } VideoRateAbbr; |
36 | 36 |
37 static const VideoFrameSizeAbbr video_frame_size_abbrs[] = { | 37 static const VideoSizeAbbr video_size_abbrs[] = { |
38 { "ntsc", 720, 480 }, | 38 { "ntsc", 720, 480 }, |
39 { "pal", 720, 576 }, | 39 { "pal", 720, 576 }, |
40 { "qntsc", 352, 240 }, /* VCD compliant NTSC */ | 40 { "qntsc", 352, 240 }, /* VCD compliant NTSC */ |
41 { "qpal", 352, 288 }, /* VCD compliant PAL */ | 41 { "qpal", 352, 288 }, /* VCD compliant PAL */ |
42 { "sntsc", 640, 480 }, /* square pixel NTSC */ | 42 { "sntsc", 640, 480 }, /* square pixel NTSC */ |
72 { "hd480", 852, 480 }, | 72 { "hd480", 852, 480 }, |
73 { "hd720", 1280, 720 }, | 73 { "hd720", 1280, 720 }, |
74 { "hd1080", 1920,1080 }, | 74 { "hd1080", 1920,1080 }, |
75 }; | 75 }; |
76 | 76 |
77 static const VideoFrameRateAbbr video_frame_rate_abbrs[]= { | 77 static const VideoRateAbbr video_rate_abbrs[]= { |
78 { "ntsc", 30000, 1001 }, | 78 { "ntsc", 30000, 1001 }, |
79 { "pal", 25, 1 }, | 79 { "pal", 25, 1 }, |
80 { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */ | 80 { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */ |
81 { "qpal", 25, 1 }, /* VCD compliant PAL */ | 81 { "qpal", 25, 1 }, /* VCD compliant PAL */ |
82 { "sntsc", 30000, 1001 }, /* square pixel NTSC */ | 82 { "sntsc", 30000, 1001 }, /* square pixel NTSC */ |
86 }; | 86 }; |
87 | 87 |
88 int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str) | 88 int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str) |
89 { | 89 { |
90 int i; | 90 int i; |
91 int n = FF_ARRAY_ELEMS(video_frame_size_abbrs); | 91 int n = FF_ARRAY_ELEMS(video_size_abbrs); |
92 char *p; | 92 char *p; |
93 int frame_width = 0, frame_height = 0; | 93 int width = 0, height = 0; |
94 | 94 |
95 for (i = 0; i < n; i++) { | 95 for (i = 0; i < n; i++) { |
96 if (!strcmp(video_frame_size_abbrs[i].abbr, str)) { | 96 if (!strcmp(video_size_abbrs[i].abbr, str)) { |
97 frame_width = video_frame_size_abbrs[i].width; | 97 width = video_size_abbrs[i].width; |
98 frame_height = video_frame_size_abbrs[i].height; | 98 height = video_size_abbrs[i].height; |
99 break; | 99 break; |
100 } | 100 } |
101 } | 101 } |
102 if (i == n) { | 102 if (i == n) { |
103 p = str; | 103 p = str; |
104 frame_width = strtol(p, &p, 10); | 104 width = strtol(p, &p, 10); |
105 if (*p) | 105 if (*p) |
106 p++; | 106 p++; |
107 frame_height = strtol(p, &p, 10); | 107 height = strtol(p, &p, 10); |
108 } | 108 } |
109 if (frame_width <= 0 || frame_height <= 0) | 109 if (width <= 0 || height <= 0) |
110 return AVERROR(EINVAL); | 110 return AVERROR(EINVAL); |
111 *width_ptr = frame_width; | 111 *width_ptr = width; |
112 *height_ptr = frame_height; | 112 *height_ptr = height; |
113 return 0; | 113 return 0; |
114 } | 114 } |
115 | 115 |
116 int av_parse_video_rate(AVRational *frame_rate, const char *arg) | 116 int av_parse_video_rate(AVRational *rate, const char *arg) |
117 { | 117 { |
118 int i; | 118 int i; |
119 int n = FF_ARRAY_ELEMS(video_frame_rate_abbrs); | 119 int n = FF_ARRAY_ELEMS(video_rate_abbrs); |
120 char *cp; | 120 char *cp; |
121 | 121 |
122 /* First, we check our abbreviation table */ | 122 /* First, we check our abbreviation table */ |
123 for (i = 0; i < n; ++i) | 123 for (i = 0; i < n; ++i) |
124 if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) { | 124 if (!strcmp(video_rate_abbrs[i].abbr, arg)) { |
125 frame_rate->num = video_frame_rate_abbrs[i].rate_num; | 125 rate->num = video_rate_abbrs[i].rate_num; |
126 frame_rate->den = video_frame_rate_abbrs[i].rate_den; | 126 rate->den = video_rate_abbrs[i].rate_den; |
127 return 0; | 127 return 0; |
128 } | 128 } |
129 | 129 |
130 /* Then, we try to parse it as fraction */ | 130 /* Then, we try to parse it as fraction */ |
131 cp = strchr(arg, '/'); | 131 cp = strchr(arg, '/'); |
132 if (!cp) | 132 if (!cp) |
133 cp = strchr(arg, ':'); | 133 cp = strchr(arg, ':'); |
134 if (cp) { | 134 if (cp) { |
135 char *cpp; | 135 char *cpp; |
136 frame_rate->num = strtol(arg, &cpp, 10); | 136 rate->num = strtol(arg, &cpp, 10); |
137 if (cpp != arg || cpp == cp) | 137 if (cpp != arg || cpp == cp) |
138 frame_rate->den = strtol(cp+1, &cpp, 10); | 138 rate->den = strtol(cp+1, &cpp, 10); |
139 else | 139 else |
140 frame_rate->num = 0; | 140 rate->num = 0; |
141 } else { | 141 } else { |
142 /* Finally we give up and parse it as double */ | 142 /* Finally we give up and parse it as double */ |
143 AVRational time_base = av_d2q(strtod(arg, 0), 1001000); | 143 AVRational time_base = av_d2q(strtod(arg, 0), 1001000); |
144 frame_rate->den = time_base.den; | 144 rate->den = time_base.den; |
145 frame_rate->num = time_base.num; | 145 rate->num = time_base.num; |
146 } | 146 } |
147 if (frame_rate->num <= 0 || frame_rate->den <= 0) | 147 if (rate->num <= 0 || rate->den <= 0) |
148 return AVERROR(EINVAL); | 148 return AVERROR(EINVAL); |
149 return 0; | 149 return 0; |
150 } | 150 } |