foobar2000 SDK  2015-08-03
dynamic_bitrate_helper.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 static unsigned g_query_settings()
4 {
5  t_int32 temp;
6  try {
8  } catch(std::exception const &) {return 9;}
9  if (temp < 0) return 0;
10  return (unsigned) temp;
11 }
12 
14 {
15  reset();
16 }
17 
19 {
20  if (!m_inited)
21  {
22  m_inited = true;
23  unsigned temp = g_query_settings();
24  if (temp > 0) {m_enabled = true; m_update_interval = 1.0 / (double) temp; }
25  else {m_enabled = false; m_update_interval = 0; }
26  m_last_duration = 0;
27  m_update_bits = 0;
28  m_update_time = 0;
29 
30  }
31 }
32 
33 void dynamic_bitrate_helper::on_frame(double p_duration,t_size p_bits)
34 {
35  init();
36  m_last_duration = p_duration;
37  m_update_time += p_duration;
38  m_update_bits += p_bits;
39 }
40 
41 bool dynamic_bitrate_helper::on_update(file_info & p_out, double & p_timestamp_delta)
42 {
43  init();
44 
45  bool ret = false;
46  if (m_enabled)
47  {
49  {
50  int val = (int) ( ((double)m_update_bits / m_update_time + 500.0) / 1000.0 );
51  if (val != p_out.info_get_bitrate_vbr())
52  {
53  p_timestamp_delta = - (m_update_time - m_last_duration); //relative to last frame beginning;
54  p_out.info_set_bitrate_vbr(val);
55  ret = true;
56  }
57  m_update_bits = 0;
58  m_update_time = 0;
59  }
60  }
61  else
62  {
63  m_update_bits = 0;
64  m_update_time = 0;
65  }
66 
67  return ret;
68 
69 }
70 
72 {
73  m_inited = false;
74 }
bool on_update(file_info &p_out, double &p_timestamp_delta)
static const GUID int32_dynamic_bitrate_display_rate
Definition: config_object.h:67
void info_set_bitrate_vbr(t_int64 val)
Definition: file_info.h:204
t_int64 info_get_bitrate_vbr() const
Definition: file_info.h:203
int32_t t_int32
Definition: int_types.h:4
void on_frame(double p_duration, t_size p_bits)
Main interface class for information about some playable object.
Definition: file_info.h:73
size_t t_size
Definition: int_types.h:48
static unsigned g_query_settings()
std::exception exception
Definition: primitives.h:193
static void g_get_data_int32(const GUID &p_guid, t_int32 &p_out)