Re: [vdr] [ANNOUNCE] AudioIndexer.patch for VDR-1.5.10 provides correct length for new radio recordings

2007-10-25 Thread Reinhard Nissl
Hi,

the attached patch is for VDR-1.4.7.

Bye.
-- 
Dipl.-Inform. (FH) Reinhard Nissl
mailto:[EMAIL PROTECTED]
diff -Nurp ../vdr-1.4.7-orig/remux.c ./remux.c
--- ../vdr-1.4.7-orig/remux.c	2006-12-01 15:46:25.0 +0100
+++ ./remux.c	2007-10-25 13:22:55.0 +0200
@@ -19,6 +19,7 @@
 #include channels.h
 #include thread.h
 #include tools.h
+#include recording.h
 
 ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int PesPayloadOffset, bool *ContinuationHeader)
 {
@@ -690,12 +691,13 @@ private:
   int frameTodo;
   int frameSize;
   int cid;
-  static bool IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize = NULL);
+  static bool IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize = NULL, int *FrameDuration = NULL);
 public:
   cAudioRepacker(int Cid);
   virtual void Reset(void);
   virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count);
   virtual int BreakAt(const uchar *Data, int Count);
+  static int GetFrameDuration(const uchar *Data, int Count, int *TrackIndex = NULL);
   };
 
 int cAudioRepacker::bitRates[2][3][16] = { // all values are specified as kbits/s
@@ -711,6 +713,25 @@ int cAudioRepacker::bitRates[2][3][16] =
   }
   };
 
+int cAudioRepacker::GetFrameDuration(const uchar *Data, int Count, int *TrackIndex)
+{
+  int PesPayloadOffset = 0;
+  ePesHeader PH = AnalyzePesHeader(Data, Count, PesPayloadOffset);
+  if (PH  phMPEG1)
+ return -1;
+
+  const uchar *Payload = Data + PesPayloadOffset;
+  const int PayloadCount = Count - PesPayloadOffset;
+
+  int FrameDuration = -1;
+  if ((Data[3]  0xE0) == 0xC0  PayloadCount = 4) {
+ if (IsValidAudioHeader(((Payload[0]  8 | Payload[1])  8 | Payload[2])  8 | Payload[3], PH == phMPEG2, NULL, FrameDuration)  TrackIndex)
+*TrackIndex = Data[3] - 0xC0;
+ }
+
+  return FrameDuration;
+}
+
 cAudioRepacker::cAudioRepacker(int Cid)
 {
   cid = Cid;
@@ -726,7 +747,7 @@ void cAudioRepacker::Reset(void)
   frameSize = 0;
 }
 
-bool cAudioRepacker::IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize)
+bool cAudioRepacker::IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize, int *FrameDuration)
 {
   int syncword   = (Header  0xFFF0)  20;
   int id = (Header  0x0008)  19;
@@ -760,32 +781,36 @@ bool cAudioRepacker::IsValidAudioHeader(
   if (emphasis == 2) // reserved
  return false;
 
-  if (FrameSize) {
- if (bitrate_index == 0)
-*FrameSize = 0;
- else {
-static int samplingFrequencies[2][4] = { // all values are specified in Hz
-  { 44100, 48000, 32000, -1 }, // MPEG 1
-  { 22050, 24000, 16000, -1 }  // MPEG 2
-  };
-
-static int slots_per_frame[2][3] = {
-  { 12, 144, 144 }, // MPEG 1, Layer I, II, III
-  { 12, 144,  72 }  // MPEG 2, Layer I, II, III
-  };
-
-int mpegIndex = 1 - id;
-int layerIndex = 3 - layer;
-
-// Layer I (i. e., layerIndex == 0) has a larger slot size
-int slotSize = (layerIndex == 0) ? 4 : 1; // bytes
-
-int br = 1000 * bitRates[mpegIndex][layerIndex][bitrate_index]; // bits/s
-int sf = samplingFrequencies[mpegIndex][sampling_frequency];
-
-int N = slots_per_frame[mpegIndex][layerIndex] * br / sf; // slots
+  if (FrameSize || FrameDuration) {
+ static int samplingFrequencies[2][4] = { // all values are specified in Hz
+   { 44100, 48000, 32000, -1 }, // MPEG 1
+   { 22050, 24000, 16000, -1 }  // MPEG 2
+   };
+
+ static int slots_per_frame[2][3] = {
+   { 12, 144, 144 }, // MPEG 1, Layer I, II, III
+   { 12, 144,  72 }  // MPEG 2, Layer I, II, III
+   };
+
+ int mpegIndex = 1 - id;
+ int layerIndex = 3 - layer;
+
+ // Layer I (i. e., layerIndex == 0) has a larger slot size
+ int slotSize = (layerIndex == 0) ? 4 : 1; // bytes
+ int sf = samplingFrequencies[mpegIndex][sampling_frequency];
+
+ if (FrameDuration)
+*FrameDuration = 9 * 8 * slotSize * slots_per_frame[mpegIndex][layerIndex] / sf;
+
+ if (FrameSize) {
+if (bitrate_index == 0)
+   *FrameSize = 0;
+else {
+   int br = 1000 * bitRates[mpegIndex][layerIndex][bitrate_index]; // bits/s
+   int N = slots_per_frame[mpegIndex][layerIndex] * br / sf; // slots
 
-*FrameSize = (N + padding_bit) * slotSize; // bytes
+   *FrameSize = (N + padding_bit) * slotSize; // bytes
+   }
 }
  }
 
@@ -1086,6 +,7 @@ public:
   virtual void Reset(void);
   virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count);
   virtual int BreakAt(const uchar *Data, int Count);
+  static int GetFrameDuration(const uchar *Data, int Count, int *TrackIndex = NULL);
   };
 
 // frameSizes are in words, i. e. multiply them by 2 to get bytes
@@ -1112,6 +1138,30 @@ int cDolbyRepacker::frameSizes[] = {
  0,0,0,0,0,0,0,0,0,0,0,0,   

Re: [vdr] [ANNOUNCE] AudioIndexer.patch for VDR-1.5.10 provides correct length for new radio recordings

2007-10-25 Thread Halim Sahin
Hi,
Thanks
Regards
Halim



___
vdr mailing list
vdr@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr


Re: [vdr] [ANNOUNCE] AudioIndexer.patch for VDR-1.5.10 provides correct length for new radio recordings

2007-10-25 Thread Stone
When I apply this patch to vdr-1.5.10, VDR no longer starts.  Could this new
Audio Indexer patch be conflicting with the dynamc ringbuffer patch?

Best Regards.
___
vdr mailing list
vdr@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr


Re: [vdr] [ANNOUNCE] AudioIndexer.patch for VDR-1.5.10 provides correct length for new radio recordings

2007-10-25 Thread Reinhard Nissl
Hi,

I'm sorry for the trouble but the patches miss a check, whether
audioIndexer exists when VDR calls cRemux::Clear(). So VDR may segfault
for non radio channels.

Attached are updated patches for VDR 1.5.10 and 1.4.7.

Bye.
-- 
Dipl.-Inform. (FH) Reinhard Nissl
mailto:[EMAIL PROTECTED]
--- ../vdr-1.5.10-orig/remux.c	2007-09-22 14:08:22.0 +0200
+++ remux.c	2007-10-25 20:51:45.0 +0200
@@ -19,6 +19,7 @@
 #include channels.h
 #include shutdown.h
 #include tools.h
+#include recording.h
 
 ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int PesPayloadOffset, bool *ContinuationHeader)
 {
@@ -690,12 +691,13 @@ private:
   int frameTodo;
   int frameSize;
   int cid;
-  static bool IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize = NULL);
+  static bool IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize = NULL, int *FrameDuration = NULL);
 public:
   cAudioRepacker(int Cid);
   virtual void Reset(void);
   virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count);
   virtual int BreakAt(const uchar *Data, int Count);
+  static int GetFrameDuration(const uchar *Data, int Count, int *TrackIndex = NULL);
   };
 
 int cAudioRepacker::bitRates[2][3][16] = { // all values are specified as kbits/s
@@ -711,6 +713,25 @@ int cAudioRepacker::bitRates[2][3][16] =
   }
   };
 
+int cAudioRepacker::GetFrameDuration(const uchar *Data, int Count, int *TrackIndex)
+{
+  int PesPayloadOffset = 0;
+  ePesHeader PH = AnalyzePesHeader(Data, Count, PesPayloadOffset);
+  if (PH  phMPEG1)
+ return -1;
+
+  const uchar *Payload = Data + PesPayloadOffset;
+  const int PayloadCount = Count - PesPayloadOffset;
+
+  int FrameDuration = -1;
+  if ((Data[3]  0xE0) == 0xC0  PayloadCount = 4) {
+ if (IsValidAudioHeader(((Payload[0]  8 | Payload[1])  8 | Payload[2])  8 | Payload[3], PH == phMPEG2, NULL, FrameDuration)  TrackIndex)
+*TrackIndex = Data[3] - 0xC0;
+ }
+
+  return FrameDuration;
+}
+
 cAudioRepacker::cAudioRepacker(int Cid)
 {
   cid = Cid;
@@ -726,7 +747,7 @@ void cAudioRepacker::Reset(void)
   frameSize = 0;
 }
 
-bool cAudioRepacker::IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize)
+bool cAudioRepacker::IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize, int *FrameDuration)
 {
   int syncword   = (Header  0xFFF0)  20;
   int id = (Header  0x0008)  19;
@@ -760,32 +781,36 @@ bool cAudioRepacker::IsValidAudioHeader(
   if (emphasis == 2) // reserved
  return false;
 
-  if (FrameSize) {
- if (bitrate_index == 0)
-*FrameSize = 0;
- else {
-static int samplingFrequencies[2][4] = { // all values are specified in Hz
-  { 44100, 48000, 32000, -1 }, // MPEG 1
-  { 22050, 24000, 16000, -1 }  // MPEG 2
-  };
-
-static int slots_per_frame[2][3] = {
-  { 12, 144, 144 }, // MPEG 1, Layer I, II, III
-  { 12, 144,  72 }  // MPEG 2, Layer I, II, III
-  };
-
-int mpegIndex = 1 - id;
-int layerIndex = 3 - layer;
-
-// Layer I (i. e., layerIndex == 0) has a larger slot size
-int slotSize = (layerIndex == 0) ? 4 : 1; // bytes
-
-int br = 1000 * bitRates[mpegIndex][layerIndex][bitrate_index]; // bits/s
-int sf = samplingFrequencies[mpegIndex][sampling_frequency];
-
-int N = slots_per_frame[mpegIndex][layerIndex] * br / sf; // slots
+  if (FrameSize || FrameDuration) {
+ static int samplingFrequencies[2][4] = { // all values are specified in Hz
+   { 44100, 48000, 32000, -1 }, // MPEG 1
+   { 22050, 24000, 16000, -1 }  // MPEG 2
+   };
+
+ static int slots_per_frame[2][3] = {
+   { 12, 144, 144 }, // MPEG 1, Layer I, II, III
+   { 12, 144,  72 }  // MPEG 2, Layer I, II, III
+   };
+
+ int mpegIndex = 1 - id;
+ int layerIndex = 3 - layer;
+
+ // Layer I (i. e., layerIndex == 0) has a larger slot size
+ int slotSize = (layerIndex == 0) ? 4 : 1; // bytes
+ int sf = samplingFrequencies[mpegIndex][sampling_frequency];
+
+ if (FrameDuration)
+*FrameDuration = 9 * 8 * slotSize * slots_per_frame[mpegIndex][layerIndex] / sf;
+
+ if (FrameSize) {
+if (bitrate_index == 0)
+   *FrameSize = 0;
+else {
+   int br = 1000 * bitRates[mpegIndex][layerIndex][bitrate_index]; // bits/s
+   int N = slots_per_frame[mpegIndex][layerIndex] * br / sf; // slots
 
-*FrameSize = (N + padding_bit) * slotSize; // bytes
+   *FrameSize = (N + padding_bit) * slotSize; // bytes
+   }
 }
  }
 
@@ -1086,6 +,7 @@ public:
   virtual void Reset(void);
   virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count);
   virtual int BreakAt(const uchar *Data, int Count);
+  static int GetFrameDuration(const uchar *Data, int Count, int *TrackIndex = NULL);
   };
 
 // frameSizes are in words, i. e. multiply them by 2 to get bytes
@@ 

Re: [vdr] [ANNOUNCE] AudioIndexer.patch for VDR-1.5.10 provides correct length for new radio recordings

2007-10-25 Thread Reinhard Nissl
Hi,

Reinhard Nissl schrieb:

 I'm sorry for the trouble but the patches miss a check, whether
 audioIndexer exists when VDR calls cRemux::Clear(). So VDR may segfault
 for non radio channels.

Am I blind? audioIndexer was not initialized to NULL for non radio channels.

Attached are updated patches for VDR 1.5.10 and 1.4.7.

Bye.
--
Dipl.-Inform. (FH) Reinhard Nissl
mailto:[EMAIL PROTECTED]
--- ../vdr-1.5.10-orig/remux.c	2007-09-22 14:08:22.0 +0200
+++ remux.c	2007-10-25 21:35:02.0 +0200
@@ -19,6 +19,7 @@
 #include channels.h
 #include shutdown.h
 #include tools.h
+#include recording.h
 
 ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int PesPayloadOffset, bool *ContinuationHeader)
 {
@@ -690,12 +691,13 @@ private:
   int frameTodo;
   int frameSize;
   int cid;
-  static bool IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize = NULL);
+  static bool IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize = NULL, int *FrameDuration = NULL);
 public:
   cAudioRepacker(int Cid);
   virtual void Reset(void);
   virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count);
   virtual int BreakAt(const uchar *Data, int Count);
+  static int GetFrameDuration(const uchar *Data, int Count, int *TrackIndex = NULL);
   };
 
 int cAudioRepacker::bitRates[2][3][16] = { // all values are specified as kbits/s
@@ -711,6 +713,25 @@ int cAudioRepacker::bitRates[2][3][16] =
   }
   };
 
+int cAudioRepacker::GetFrameDuration(const uchar *Data, int Count, int *TrackIndex)
+{
+  int PesPayloadOffset = 0;
+  ePesHeader PH = AnalyzePesHeader(Data, Count, PesPayloadOffset);
+  if (PH  phMPEG1)
+ return -1;
+
+  const uchar *Payload = Data + PesPayloadOffset;
+  const int PayloadCount = Count - PesPayloadOffset;
+
+  int FrameDuration = -1;
+  if ((Data[3]  0xE0) == 0xC0  PayloadCount = 4) {
+ if (IsValidAudioHeader(((Payload[0]  8 | Payload[1])  8 | Payload[2])  8 | Payload[3], PH == phMPEG2, NULL, FrameDuration)  TrackIndex)
+*TrackIndex = Data[3] - 0xC0;
+ }
+
+  return FrameDuration;
+}
+
 cAudioRepacker::cAudioRepacker(int Cid)
 {
   cid = Cid;
@@ -726,7 +747,7 @@ void cAudioRepacker::Reset(void)
   frameSize = 0;
 }
 
-bool cAudioRepacker::IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize)
+bool cAudioRepacker::IsValidAudioHeader(uint32_t Header, bool Mpeg2, int *FrameSize, int *FrameDuration)
 {
   int syncword   = (Header  0xFFF0)  20;
   int id = (Header  0x0008)  19;
@@ -760,32 +781,36 @@ bool cAudioRepacker::IsValidAudioHeader(
   if (emphasis == 2) // reserved
  return false;
 
-  if (FrameSize) {
- if (bitrate_index == 0)
-*FrameSize = 0;
- else {
-static int samplingFrequencies[2][4] = { // all values are specified in Hz
-  { 44100, 48000, 32000, -1 }, // MPEG 1
-  { 22050, 24000, 16000, -1 }  // MPEG 2
-  };
-
-static int slots_per_frame[2][3] = {
-  { 12, 144, 144 }, // MPEG 1, Layer I, II, III
-  { 12, 144,  72 }  // MPEG 2, Layer I, II, III
-  };
-
-int mpegIndex = 1 - id;
-int layerIndex = 3 - layer;
-
-// Layer I (i. e., layerIndex == 0) has a larger slot size
-int slotSize = (layerIndex == 0) ? 4 : 1; // bytes
-
-int br = 1000 * bitRates[mpegIndex][layerIndex][bitrate_index]; // bits/s
-int sf = samplingFrequencies[mpegIndex][sampling_frequency];
-
-int N = slots_per_frame[mpegIndex][layerIndex] * br / sf; // slots
+  if (FrameSize || FrameDuration) {
+ static int samplingFrequencies[2][4] = { // all values are specified in Hz
+   { 44100, 48000, 32000, -1 }, // MPEG 1
+   { 22050, 24000, 16000, -1 }  // MPEG 2
+   };
+
+ static int slots_per_frame[2][3] = {
+   { 12, 144, 144 }, // MPEG 1, Layer I, II, III
+   { 12, 144,  72 }  // MPEG 2, Layer I, II, III
+   };
+
+ int mpegIndex = 1 - id;
+ int layerIndex = 3 - layer;
+
+ // Layer I (i. e., layerIndex == 0) has a larger slot size
+ int slotSize = (layerIndex == 0) ? 4 : 1; // bytes
+ int sf = samplingFrequencies[mpegIndex][sampling_frequency];
+
+ if (FrameDuration)
+*FrameDuration = 9 * 8 * slotSize * slots_per_frame[mpegIndex][layerIndex] / sf;
+
+ if (FrameSize) {
+if (bitrate_index == 0)
+   *FrameSize = 0;
+else {
+   int br = 1000 * bitRates[mpegIndex][layerIndex][bitrate_index]; // bits/s
+   int N = slots_per_frame[mpegIndex][layerIndex] * br / sf; // slots
 
-*FrameSize = (N + padding_bit) * slotSize; // bytes
+   *FrameSize = (N + padding_bit) * slotSize; // bytes
+   }
 }
  }
 
@@ -1086,6 +,7 @@ public:
   virtual void Reset(void);
   virtual void Repack(cRingBufferLinear *ResultBuffer, const uchar *Data, int Count);
   virtual int BreakAt(const uchar *Data, int Count);
+  static int GetFrameDuration(const uchar *Data, int