Skip to content
This repository
Browse code

Merge pull request #2701 from FernetMenta/streamfix

dmuxer streams: some fixes after #1757
  • Loading branch information...
commit 854b740d322b170193ac8320335b53123263fe32 2 parents dca4014 + f86d779
Rainer Hochecker authored May 09, 2013
30  xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -646,7 +646,10 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
646 646
 
647 647
       return pPacket;
648 648
     }
649  
-    else if (m_pkt.pkt.size < 0 || !GetStreamInternal(m_pkt.pkt.stream_index))
  649
+    // check size and stream index for being in a valid range
  650
+    else if (m_pkt.pkt.size < 0 ||
  651
+             m_pkt.pkt.stream_index < 0 ||
  652
+             m_pkt.pkt.stream_index >= m_pFormatContext->nb_streams)
650 653
     {
651 654
       // XXX, in some cases ffmpeg returns a negative packet size
652 655
       if(m_pFormatContext->pb && !m_pFormatContext->pb->eof_reached)
@@ -751,7 +754,9 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
751 754
           }
752 755
         }
753 756
 
754  
-        pPacket->iStreamId = m_pkt.pkt.stream_index; // XXX just for now
  757
+        // store internal id until we know the continuous id presented to player
  758
+        // the stream might not have been created yet
  759
+        pPacket->iStreamId = m_pkt.pkt.stream_index;
755 760
       }
756 761
       m_pkt.result = -1;
757 762
       m_dllAvCodec.av_free_packet(&m_pkt.pkt);
@@ -772,7 +777,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
772 777
         stream->codec != m_pFormatContext->streams[pPacket->iStreamId]->codec->codec_id)
773 778
     {
774 779
       // content has changed, or stream did not yet exist
775  
-      AddStream(pPacket->iStreamId);
  780
+      stream = AddStream(pPacket->iStreamId);
776 781
     }
777 782
     // we already check for a valid m_streams[pPacket->iStreamId] above
778 783
     else if (stream->type == STREAM_AUDIO)
@@ -781,7 +786,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
781 786
           ((CDemuxStreamAudio*)stream)->iSampleRate != m_pFormatContext->streams[pPacket->iStreamId]->codec->sample_rate)
782 787
       {
783 788
         // content has changed
784  
-        AddStream(pPacket->iStreamId);
  789
+        stream = AddStream(pPacket->iStreamId);
785 790
       }
786 791
     }
787 792
     else if (stream->type == STREAM_VIDEO)
@@ -790,9 +795,17 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
790 795
           ((CDemuxStreamVideo*)stream)->iHeight != m_pFormatContext->streams[pPacket->iStreamId]->codec->height)
791 796
       {
792 797
         // content has changed
793  
-        AddStream(pPacket->iStreamId);
  798
+        stream = AddStream(pPacket->iStreamId);
794 799
       }
795 800
     }
  801
+    if (!stream)
  802
+    {
  803
+      CLog::Log(LOGERROR, "CDVDDemuxFFmpeg::AddStream - internal error, stream is null");
  804
+      CDVDDemuxUtils::FreeDemuxPacket(pPacket);
  805
+      return NULL;
  806
+    }
  807
+    // set continuous stream id for player
  808
+    pPacket->iStreamId = stream->iId;
796 809
   }
797 810
   return pPacket;
798 811
 }
@@ -995,7 +1008,7 @@ void CDVDDemuxFFmpeg::DisposeStreams()
995 1008
   m_stream_index.clear();
996 1009
 }
997 1010
 
998  
-void CDVDDemuxFFmpeg::AddStream(int iId)
  1011
+CDemuxStream* CDVDDemuxFFmpeg::AddStream(int iId)
999 1012
 {
1000 1013
   AVStream* pStream = m_pFormatContext->streams[iId];
1001 1014
   if (pStream)
@@ -1186,7 +1199,7 @@ void CDVDDemuxFFmpeg::AddStream(int iId)
1186 1199
 
1187 1200
 #ifdef HAVE_LIBBLURAY
1188 1201
     if( m_pInput->IsStreamType(DVDSTREAM_TYPE_BLURAY) )
1189  
-      static_cast<CDVDInputStreamBluray*>(m_pInput)->GetStreamInfo(pStream->id, m_streams[iId]->language);
  1202
+      static_cast<CDVDInputStreamBluray*>(m_pInput)->GetStreamInfo(pStream->id, stream->language);
1190 1203
 #endif
1191 1204
     if( m_pInput->IsStreamType(DVDSTREAM_TYPE_DVD) )
1192 1205
     {
@@ -1219,7 +1232,10 @@ void CDVDDemuxFFmpeg::AddStream(int iId)
1219 1232
       stream->iPhysicalId = pStream->id;
1220 1233
 
1221 1234
     AddStream(iId, stream);
  1235
+    return stream;
1222 1236
   }
  1237
+  else
  1238
+    return NULL;
1223 1239
 }
1224 1240
 
1225 1241
 /**
2  xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h
@@ -121,7 +121,7 @@ class CDVDDemuxFFmpeg : public CDVDDemux
121 121
   friend class CDemuxStreamSubtitleFFmpeg;
122 122
 
123 123
   int ReadFrame(AVPacket *packet);
124  
-  void AddStream(int iId);
  124
+  CDemuxStream* AddStream(int iId);
125 125
   void AddStream(int iId, CDemuxStream* stream);
126 126
   CDemuxStream* GetStreamInternal(int iStreamId);
127 127
   void CreateStreams(unsigned int program = UINT_MAX);

0 notes on commit 854b740

Please sign in to comment.
Something went wrong with that request. Please try again.