Line data Source code
1 : /*
2 : * GPAC - Multimedia Framework C SDK
3 : *
4 : * Authors: Deniz Ugur, Romain Bouqueau, Sohaib Larbi
5 : * Copyright (c) Motion Spell
6 : * All rights reserved
7 : *
8 : * This file is part of the GPAC/GStreamer wrapper
9 : *
10 : * This GPAC/GStreamer wrapper is free software; you can redistribute it
11 : * and/or modify it under the terms of the GNU Affero General Public License
12 : * as published by the Free Software Foundation; either version 3, or (at
13 : * your option) any later version.
14 : *
15 : * This GPAC/GStreamer wrapper is distributed in the hope that it will be
16 : * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : * GNU Affero General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU Affero General Public
21 : * License along with this library; see the file LICENSE. If not, write to
22 : * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 : *
24 : */
25 :
26 : #include "lib/time.h"
27 :
28 : guint64
29 19593 : gpac_time_rescale_with_fps(GstClockTime time,
30 : GF_Fraction fps,
31 : guint64 desired_timescale)
32 : {
33 19593 : if (!GST_CLOCK_TIME_IS_VALID(time) || !desired_timescale)
34 3 : return 0;
35 :
36 : // Timescale is already in the desired timescale
37 19590 : if (GST_SECOND == desired_timescale)
38 0 : return time;
39 :
40 : // Calculate the frame duration in GST_SECOND
41 19590 : guint64 frame_duration = gf_timestamp_rescale(GST_SECOND, fps.num, fps.den);
42 :
43 : // Convert the given time to the desired timescale
44 : guint64 frame_tick =
45 19590 : gf_timestamp_rescale(desired_timescale, fps.num, fps.den);
46 : guint64 rescaled_time =
47 19590 : gf_timestamp_rescale(time, frame_duration, frame_tick);
48 :
49 19590 : return rescaled_time;
50 : }
|