Aktuelle Zeit: 24.09.2020 17:25

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]




Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Autor Nachricht
 Betreff des Beitrags: Webcam Jpeg Stream stützt nach einer Weile ab (Gefixt)
BeitragVerfasst: 09.08.2016 16:27 
Offline

Registriert: 06.04.2005 22:44
Hallo Leute,

ich habe hier einen Video Server ABUS TV7206.
Bei diesem hole ich mit folgendem Programm einen jpeg Stream ab.
Das Programm läuft 30-60 Sekunden und schmiert dann immer mit Ungültigen Speicherzugiff ab.


Keine Ahnung beim Netzwerk oder bei den Bildern.
Sieht einer von euch, wo ich einen Fehler gemacht habe.

Bildergöße immer < 50K

Gruß Thomas

Gefixt:
in der Procedure PicWork() am Ende den String PicHeader ist übergelaufen

Code:
     
      If PicLen = 0
        Action()
        PicHeader = ""
        PicState = #PicStateHeader
      EndIf
  EndSelect


und es geht ......

Code:
EnableExplicit

#Mem = 30000
#PicMem = 100000
#ThreadCount = 1


Structure Thread
  Thread.i
  Mutex.i
  Quit.i
  Doit.i
  Result.i
EndStructure

 


Global.i IP_Socket,IP_Port,MemLen,WindowMain,GadgetPic,Quit,PicLen,PicState,PicSelect,PicID0,PicID1
Global.i WindowStatusbar

Global.s IP_Adress,PicHttp,PicHeader,HTTPend
Global *Mem,*PicMem0,*PicPointer0,*PicMem1,*PicPointer1,*Pointer

Global Dim Thread.Thread(#ThreadCount)


Enumeration Thread
  #ThreadNetwork
EndEnumeration

Enumeration
  #PicStateIdle
  #PicStateHTTP
  #PicStateHeader
  #PicStateRead
  #PicStateEnd
EndEnumeration

UseJPEGImageDecoder()

*Mem = AllocateMemory(#Mem)
*PicMem0 = AllocateMemory(#PicMem)
*PicMem1 = AllocateMemory(#PicMem)

If *Mem = 0 Or *PicMem0= 0 Or *PicMem1= 0
  End
EndIf

If Not InitNetwork()
  End
EndIf


Procedure InitThread()
  Protected.i i
 
  For I = 0 To #ThreadCount-1
    Thread(i)\Doit=   CreateSemaphore(0)
    Thread(i)\Quit=   CreateSemaphore(0)
    Thread(i)\Mutex=   CreateMutex()
    Thread(i)\Thread = 0
  Next I
EndProcedure
Procedure DeInitThread()
  Protected.i i,Timer 
 
  For i = 0 To #ThreadCount-1
    SignalSemaphore(Thread(i)\Quit)
    Timer = ElapsedMilliseconds()
    While Timer+2000 > ElapsedMilliseconds()
      If Not IsThread(thread(i)\Thread) 
        Thread(i)\Thread = 0 
        Break
      EndIf
    Wend
    If Thread(i)\Thread
      MessageRequester("Error","Can't stop Thread Number:"+Str(i))
    EndIf
  Next I
EndProcedure
Procedure.i Min(A.i,B.i)
  Protected Result
 
  Result = A
  If B<A
    Result = B
  EndIf
  ProcedureReturn Result
EndProcedure
Procedure Init()
  IP_Adress = "192.168.20.102" 
  IP_Port = 80
  HTTPend = Chr(13)+Chr(10)+Chr(13)+Chr(10)
  WindowMain = OpenWindow(#PB_Any,100,100,706,600,"AbusServer V1")
  GadgetPic = ImageGadget(#PB_Any,0,0,704,576,0)
  WindowStatusbar = CreateStatusBar(#PB_Any,WindowID(WindowMain))
  AddStatusBarField(50)
  AddStatusBarField(200)
  AddStatusBarField(200)
  AddStatusBarField(200)
EndProcedure
Procedure.s Fstr(s.s)
  s= ReplaceString(s,"\n",Chr(10))
  s= ReplaceString(s,"\r",Chr(13))
  ProcedureReturn s
EndProcedure
Procedure event()
  Protected.i WindowEvent
 
  WindowEvent = WindowEvent()
 
  Select WindowEvent
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
EndProcedure
Procedure Connect()
  IP_Socket = OpenNetworkConnection(IP_Adress,IP_Port)
  ProcedureReturn IP_Socket
EndProcedure
Procedure DisConnect()
  CloseNetworkConnection(IP_Socket)
EndProcedure
Procedure Request()
  If IP_Socket
    SendNetworkString(IP_Socket,fstr("GET /video2.mjpg HTTP/1.1\r\n\r\n"))
  EndIf   
EndProcedure
Procedure.i RevVal(S.s,Ignore.i)
  Protected.s Res
  Protected.i P
 
  P = Len(S)-Ignore
  Res=""
  While Asc(Mid(s,P,1)) >='0' And  Asc(Mid(s,P,1)) <='9'
    Res = Mid(s,P,1) + Res 
    P-1
  Wend
  ProcedureReturn Val(Res)
EndProcedure
Procedure PicClock()
 
  If PicSelect
    StartDrawing(ImageOutput(PicID1))
  Else
    StartDrawing(ImageOutput(PicID0))
  EndIf
 
  DrawingMode(#PB_2DDrawing_Transparent)
 
  DrawText(20,20,FormatDate("%hh:%ii:%ss",Date()), RGB(255, 255,255))
  StopDrawing()
 
EndProcedure

   
   
   
Procedure Action()
 
  StatusBarText(WindowStatusbar,0,"Pic:"+Str(PicSelect))
 
  If PicSelect
    If PicID1
      FreeImage(PicID1)
    EndIf   
    Debug "Catch1s"
    PicID1 = CatchImage(#PB_Any,*PicMem1,#PicMem)
    Debug "Catch1r"
    If PicID1
      PicClock()
      SetGadgetState(GadgetPic,ImageID(PicID1)) 
      Debug "Set1"
    EndIf
   
  Else
    If PicID0
      FreeImage(PicID0)
    EndIf   
    Debug "Catch0s"
    PicID0 =  CatchImage(#PB_Any,*PicMem0,#PicMem)
    Debug "Catch0r"
    If PicID0
      PicClock()
      SetGadgetState(GadgetPic,ImageID(PicID0)) 
      Debug "Set0"
    EndIf
  EndIf

EndProcedure
Procedure.i PicWork(L.i)
  Protected.i ReadLen
 
  Select PicState
    Case #PicStateIdle
      PicHttp = ""
      PicHeader = ""
      PicState = #PicStateHTTP
    Case #PicStateHTTP
      While L
        PicHttp+ PeekS(*Pointer,1) 
        L-1
        *Pointer+1
        If Right(PicHttp,Len(HTTPend)) = HTTPend
          PicState = #PicStateHeader
          Break
        EndIf
      Wend
    Case #PicStateHeader
      While L
        PicHeader+ PeekS(*Pointer,1) 
        L-1
        *Pointer+1
        If Right(PicHeader,Len(HTTPend)) = HTTPend
          StatusBarText(WindowStatusbar,3,Mid(PicHeader,Len(PicHeader)-20,21-Len(HTTPend)))
          PicLen = RevVal(PicHeader,Len(HTTPend))       
          PicState = #PicStateRead
          PicSelect = 1 - PicSelect
          *PicPointer1 = *PicMem1
          *PicPointer0 = *PicMem0
          Break
        EndIf
      Wend
    Case #PicStateRead
      Readlen = min(L,PicLen)
      StatusBarText(WindowStatusbar,1,"PicLen:"+Str(PicLen))
      If PicSelect
        CopyMemory(*Pointer,*PicPointer1,ReadLen)
        *PicPointer1 + ReadLen
      Else
        CopyMemory(*Pointer,*PicPointer0,ReadLen)
        *PicPointer0 + ReadLen
      EndIf
     
      PicLen - ReadLen
      *Pointer + ReadLen
      L - ReadLen   
     
      If l < 0
        Debug "L-dead"
        End
      EndIf
     
     
      If PicLen = 0
        Action()
        PicState = #PicStateHeader
      EndIf
  EndSelect
 
  StatusBarText(WindowStatusbar,2,"MemLen:"+Str(L))
 
  ProcedureReturn l
EndProcedure

Procedure Network(void.i)
  While (Not TrySemaphore(Thread(#ThreadNetwork)\Quit)) And IP_Socket
    If IP_Socket
      Select NetworkClientEvent(IP_Socket)
        Case #PB_NetworkEvent_None
        Case #PB_NetworkEvent_Data
          MemLen = ReceiveNetworkData(IP_Socket,*Mem,#Mem)
          *Pointer = *Mem
          While MemLen
            MemLen = PicWork(MemLen)
          Wend
        Case #PB_NetworkEvent_Disconnect
          Debug "Dead"
          Quit = 1
      EndSelect
    EndIf
  Wend
EndProcedure

 


 
Init()
InitThread()

If Connect()
  Request()
  Thread(#ThreadNetwork)\Thread = CreateThread(@Network(),0)   
 
Else
  quit = 1
EndIf

Repeat
  Event()
 
  If IP_Socket = 0
    Quit = 1
  EndIf
 
  Delay(2)
Until Quit = 1

DeInitThread()
If IP_Socket
  Disconnect()
EndIf


End



Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]


Wer ist online?

Mitglieder in diesem Forum: Exabot [Bot] und 10 Gäste


Sie dürfen keine neuen Themen in diesem Forum erstellen.
Sie dürfen keine Antworten zu Themen in diesem Forum erstellen.
Sie dürfen Ihre Beiträge in diesem Forum nicht ändern.
Sie dürfen Ihre Beiträge in diesem Forum nicht löschen.

Suche nach:
Gehe zu:  

 


Powered by phpBB © 2008 phpBB Group | Deutsche Übersetzung durch phpBB.de
subSilver+ theme by Canver Software, sponsor Sanal Modifiye