1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Miscellaneous helper API definitions
12 * Copyright (c) 2007 Michael Sevakis
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "mpegplayer.h"
26 /* Ensures direction is -1 or 1 and margin is properly initialized */
27 void stream_scan_normalize(struct stream_scan
*sk
)
31 sk
->dir
= SSCAN_FORWARD
;
36 sk
->dir
= SSCAN_REVERSE
;
41 /* Moves a scan cursor. If amount is positive, the increment is in the scan
42 * direction, otherwise opposite the scan direction */
43 void stream_scan_offset(struct stream_scan
*sk
, off_t by
)
45 off_t bydir
= by
*sk
->dir
;
52 void ts_to_hms(uint32_t pts
, struct hms
*hms
)
54 hms
->frac
= pts
% TS_SECOND
;
55 hms
->sec
= pts
/ TS_SECOND
;
56 hms
->min
= hms
->sec
/ 60;
57 hms
->hrs
= hms
->min
/ 60;
62 void hms_format(char *buf
, size_t bufsize
, struct hms
*hms
)
64 /* Only display hours if nonzero */
67 rb
->snprintf(buf
, bufsize
, "%u:%02u:%02u",
68 hms
->hrs
, hms
->min
, hms
->sec
);
72 rb
->snprintf(buf
, bufsize
, "%u:%02u",
78 uint32_t muldiv_uint32(uint32_t multiplicand
,
84 uint64_t prod
= (uint64_t)multiplier
*multiplicand
+ divisor
/2;
86 if ((uint32_t)(prod
>> 32) < divisor
)
87 return (uint32_t)(prod
/ divisor
);
89 else if (multiplicand
== 0 || multiplier
== 0)
91 return 0; /* 0/0 = 0 : yaya */
93 /* else (> 0) / 0 = UINT32_MAX */
95 return UINT32_MAX
; /* Saturate */