Skip to content

Commit 5be77c3

Browse files
authored
Improved oapv_version function (#104)
* support 4-byte version number Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com> * added error handling code in oapv_version Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com> --------- Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>
1 parent 1d79983 commit 5be77c3

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

app/oapv_app_dec.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ int main(int argc, const char **argv)
377377
memset(&ofrms, 0, sizeof(oapv_frms_t));
378378

379379
// print logo
380+
char version[16];
381+
oapv_version(version, sizeof(version));
382+
380383
logv2(" ____ ___ ___ _ __\n");
381-
logv2(" / __ \\___ ___ ___ / _ | / _ \\ | / / Decoder (v%s)\n", oapv_version());
384+
logv2(" / __ \\___ ___ ___ / _ | / _ \\ | / / Decoder (v%s)\n", version);
382385
logv2("/ /_/ / _ \\/ -_) _ \\/ __ |/ ___/ |/ / \n");
383386
logv2("\\____/ .__/\\__/_//_/_/ |_/_/ |___/ \n");
384387
logv2(" /_/ \n");

app/oapv_app_enc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,11 @@ int main(int argc, const char **argv)
598598
const int num_frames = MAX_NUM_FRMS; // number of frames in an access unit
599599

600600
// print logo
601+
char version[16];
602+
oapv_version(version, sizeof(version));
603+
601604
logv2(" ____ ___ ___ _ __\n");
602-
logv2(" / __ \\___ ___ ___ / _ | / _ \\ | / / Encoder (v%s)\n", oapv_version());
605+
logv2(" / __ \\___ ___ ___ / _ | / _ \\ | / / Encoder (v%s)\n", version);
603606
logv2("/ /_/ / _ \\/ -_) _ \\/ __ |/ ___/ |/ / \n");
604607
logv2("\\____/ .__/\\__/_//_/_/ |_/_/ |___/ \n");
605608
logv2(" /_/ \n");

inc/oapv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,8 @@ OAPV_EXPORT int oapvd_info(void *au, int au_size, oapv_au_info_t *aui);
680680
/*****************************************************************************
681681
* openapv version
682682
*****************************************************************************/
683-
OAPV_EXPORT const char *oapv_version(void);
683+
OAPV_EXPORT unsigned int oapv_version(char *ver, int size);
684+
684685

685686
#ifdef __cplusplus
686687
} /* extern "C" */

src/oapv.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,10 +2153,15 @@ int oapvd_info(void *au, int au_size, oapv_au_info_t *aui)
21532153
#endif // ENABLE_DECODER
21542154
///////////////////////////////////////////////////////////////////////////////
21552155

2156-
const char *oapv_version(void)
2156+
unsigned int oapv_version(char *ver, int size)
21572157
{
2158-
static char oapv_version_string[16];
2159-
snprintf(oapv_version_string, sizeof(oapv_version_string), "%d.%d.%d.%d",
2160-
OAPV_VER_APISET, OAPV_VER_MAJOR, OAPV_VER_MINOR, OAPV_VER_PATCH);
2161-
return (char*)oapv_version_string;
2158+
if(ver != NULL) {
2159+
int written = snprintf(ver, size, "%d.%d.%d.%d",
2160+
OAPV_VER_APISET, OAPV_VER_MAJOR, OAPV_VER_MINOR, OAPV_VER_PATCH);
2161+
// check if snprintf encountered an error or if the output was truncated.
2162+
if (written < 0 || written >= size) {
2163+
return OAPV_ERR_INVALID_ARGUMENT;
2164+
}
2165+
}
2166+
return OAPV_VER_NUM;
21622167
}

0 commit comments

Comments
 (0)