Skip to content
This repository
Browse code

Merge pull request #2735 from davilla/add-avformat_network-bits

fixed, add avformat_network_init/avformat_network_deinit
  • Loading branch information...
commit 474a8e5180be422322919de3b1aa05f89777385f 2 parents bf91362 + b8bfb1c
davilla authored May 12, 2013
39  lib/DllAvFormat.h
@@ -65,6 +65,8 @@ class DllAvFormatInterface
65 65
 public:
66 66
   virtual ~DllAvFormatInterface() {}
67 67
   virtual void av_register_all_dont_call(void)=0;
  68
+  virtual void avformat_network_init_dont_call(void)=0;
  69
+  virtual void avformat_network_deinit_dont_call(void)=0;
68 70
   virtual AVInputFormat *av_find_input_format(const char *short_name)=0;
69 71
   virtual void avformat_close_input(AVFormatContext **s)=0;
70 72
   virtual int av_read_frame(AVFormatContext *s, AVPacket *pkt)=0;
@@ -116,6 +118,8 @@ class DllAvFormat : public DllDynamic, DllAvFormatInterface
116 118
     return ::av_register_all();
117 119
   } 
118 120
   virtual void av_register_all_dont_call() { *(volatile int* )0x0 = 0; } 
  121
+  virtual void avformat_network_init_dont_call() { *(volatile int* )0x0 = 0; } 
  122
+  virtual void avformat_network_deinit_dont_call() { *(volatile int* )0x0 = 0; } 
119 123
   virtual AVInputFormat *av_find_input_format(const char *short_name) { return ::av_find_input_format(short_name); }
120 124
   virtual void avformat_close_input(AVFormatContext **s) { ::avformat_close_input(s); }
121 125
   virtual int av_read_frame(AVFormatContext *s, AVPacket *pkt) { return ::av_read_frame(s, pkt); }
@@ -162,9 +166,19 @@ class DllAvFormat : public DllDynamic, DllAvFormatInterface
162 166
 #if !defined(TARGET_DARWIN)
163 167
     CLog::Log(LOGDEBUG, "DllAvFormat: Using libavformat system library");
164 168
 #endif
  169
+    CSingleLock lock(DllAvCodec::m_critSection);
  170
+    if (++m_avformat_refcnt == 1)
  171
+      ::avformat_network_init();
165 172
     return true;
166 173
   }
167  
-  virtual void Unload() {}
  174
+  virtual void Unload() {
  175
+    CSingleLock lock(DllAvCodec::m_critSection);
  176
+    if (--m_avformat_refcnt == 0)
  177
+      ::avformat_network_deinit();
  178
+  }
  179
+
  180
+protected:
  181
+  static int m_avformat_refcnt;
168 182
 };
169 183
 
170 184
 #else
@@ -176,6 +190,8 @@ class DllAvFormat : public DllDynamic, DllAvFormatInterface
176 190
   LOAD_SYMBOLS()
177 191
 
178 192
   DEFINE_METHOD0(void, av_register_all_dont_call)
  193
+  DEFINE_METHOD0(void, avformat_network_init_dont_call)
  194
+  DEFINE_METHOD0(void, avformat_network_deinit_dont_call)
179 195
   DEFINE_METHOD1(AVInputFormat*, av_find_input_format, (const char *p1))
180 196
   DEFINE_METHOD1(void, avformat_close_input, (AVFormatContext **p1))
181 197
   DEFINE_METHOD1(int, av_read_play, (AVFormatContext *p1))
@@ -212,6 +228,8 @@ class DllAvFormat : public DllDynamic, DllAvFormatInterface
212 228
   DEFINE_METHOD2(int, av_write_frame  , (AVFormatContext *p1, AVPacket *p2))
213 229
   BEGIN_METHOD_RESOLVE()
214 230
     RESOLVE_METHOD_RENAME(av_register_all, av_register_all_dont_call)
  231
+    RESOLVE_METHOD_RENAME(avformat_network_init,   avformat_network_init_dont_call)
  232
+    RESOLVE_METHOD_RENAME(avformat_network_deinit, avformat_network_deinit_dont_call)
215 233
     RESOLVE_METHOD(av_find_input_format)
216 234
     RESOLVE_METHOD(avformat_close_input)
217 235
     RESOLVE_METHOD(av_read_frame)
@@ -265,8 +283,25 @@ class DllAvFormat : public DllDynamic, DllAvFormatInterface
265 283
   {
266 284
     if (!m_dllAvCodec.Load())
267 285
       return false;
268  
-    return DllDynamic::Load();
  286
+    bool loaded = DllDynamic::Load();
  287
+
  288
+    CSingleLock lock(DllAvCodec::m_critSection);
  289
+    if (++m_avformat_refcnt == 1 && loaded)
  290
+      avformat_network_init_dont_call();
  291
+    return loaded;
269 292
   }
  293
+
  294
+  virtual void Unload()
  295
+  {
  296
+    CSingleLock lock(DllAvCodec::m_critSection);
  297
+    if (--m_avformat_refcnt == 0 && DllDynamic::IsLoaded())
  298
+      avformat_network_deinit_dont_call();
  299
+
  300
+    DllDynamic::Unload();
  301
+  }
  302
+
  303
+protected:
  304
+  static int m_avformat_refcnt;
270 305
 };
271 306
 
272 307
 #endif
1  xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -92,6 +92,7 @@ void CDemuxStreamSubtitleFFmpeg::GetStreamInfo(std::string& strInfo)
92 92
 
93 93
 // these need to be put somewhere that are compiled, we should have some better place for it
94 94
 
  95
+int DllAvFormat::m_avformat_refcnt = 0;
95 96
 CCriticalSection DllAvCodec::m_critSection;
96 97
 static CCriticalSection m_logSection;
97 98
 std::map<uintptr_t, CStdString> g_logbuffer;

0 notes on commit 474a8e5

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