Android Question RSVideoRecord library problem.

tigrot

Well-Known Member
Licensed User
Longtime User
I have an APP which runs very well. It takes pictures and send them in sequence to a server via a TCP connection. I use CamEx to take pictures. The customer asked me to take a movie too and store it on the local memory. This works very well with RSVideoRecord library. I get the movie, store it and repeat the process many times. In the same app I use CamEx to take pictures and I'm able to get an unlimited number of them. But after this action, the Movie camera doesn't work since the Record_ready (after record_initialize) reports success=false. Doing the reversed action (movie camera---> take pictures) works ok!
In extended log there is no further information, no bad parameter...
The code to start the movie camera is:
B4X:
'initialize panel1
      Activity.LoadLayout("5")
    record.Initialize(Panel1, "record")
Sub record_Ready (Success As Boolean)
    If Success Then
        Dim OS As OperatingSystem
       
        OS.Initialize("OS")
        Dim extmem As Long = OS.AvailableExternalMemorySize
        Dim intmem As Long = OS.AvailableInternalMemorySize
        Dim totmem As Long
        If extmem >intmem Then
          totmem = extmem   
          dirimage= File.DirDefaultExternal
        Else
          totmem = intmem
          dirimage= File.DirInternalCache
        End If
        If totmem< 30000000 Then
              Msgbox ("Spazio insufficiente / Few disk space", "Disk Space")
              record.Release
              Return
        End If 
        Dim tottime As Double = totmem/1500000 ' ottiene i minuti
        Dim dsply As String= "Rec.max minutes: " & NumberFormat2(tottime,1,3,2,False)
   
        If sleep=False Then
          setsleep_click
        End If
        btntakepicture.Enabled=False
        record.StartPreview
        'ToastMessageShow("Preview started.",False)
        Try
          record.unlockCamera
        Catch
        End Try
        record.initMediaRecorder()
        record.AudioSource = 5
        record.VideoSource = 1
        record.OutputFormat = 2
        record.setScreenSize(320,240)
        record.AudioEncoder = 1
        record.VideoEncoder = 2
        record.setOutputFile(dirimage , Mioangelo.userx)
        record.setPreviewDisplay
       
        ToastMessageShow("Initialized.",False)
        record.prepare
        Try
          record.start
        Catch
            Log(LastException.Message)
        End Try
        'ToastMessageShow("Started.",False)
        btntakepicture.Enabled=True
        ToastMessageShow(dsply,True)
        filma=True
    Else
        ToastMessageShow("Cannot open camera.", True)
        Panel1.RemoveView
        btntakepicture.RemoveView
    End If
end sub

This code will end the movie activity:
B4X:
Sub stopvideo
    record.stop
    record.resetMediaRecorder
    record.releaseMediaRecorder
    record.lockCamera
    'ToastMessageShow("Stopped.",False)
    record.StopPreview
    record.Release
    'ToastMessageShow("Released.",False)
    Panel1.RemoveView
    btntakepicture.RemoveView
    ToastMessageShow("Video Pronto/Video Ready",True)
    If sleep=True Then
        setsleep_click
    End If
    Activity.Title= actlabel
End Sub

This is the code to start picture handling:

B4X:
camEx.Initialize(Panel1, frontCamera, Me, "Camera1")

B4X:
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.StartPreview
        Log("Supported sizes:")
        For Each size As CameraSize In camEx.GetSupportedPicturesSizes
            Log(size.Width & "x" & size.Height)
        Next
        camEx.SetJpegQuality(90)
        Log(camEx.GetSupportedFlashModes)
        camEx.SetPictureSize(320,240)
        camEx.CommitParameters
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

This code sends the pictures:
B4X:
Sub Camera1_Preview (PreviewPic() As Byte)
           Dim jpeg() As Byte = camEx.PreviewImageToJpeg(PreviewPic, 70)
           CallSubDelayed2(picturesender, "Send", jpeg) ' this sub sends the picture...
        End Sub

This codes terminates the pictures' acquire...
B4X:
camEx.StopPreview
camEx.Release

Does anybody have an aswer for such a beaviour?

Thank very much for you time...

Mauro
 

JordiCP

Expert
Licensed User
Longtime User
You should find it in the class, near the end. Check for the latest version HERE

B4X:
'This method should only be called if you need to immediately release the camera.
'For example if you need to start another application that depends on the camera.
Public Sub CloseNow
    cam.Release
    r.target = cam
    r.RunMethod2("releaseCameras", True, "java.lang.boolean")
End Sub
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Thank you very much for your kind help. This is a very efficient forum(for the people is smart indeed here!).
Sorry the CloseNow didn't help. Till the APP was sleeping or actrive I was never able to launch the RSVideorecord activity. Dunno why!
Maybe in my next life I'll find an answer!
Thank you very much again for your precious time.

Mauro
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I solved the issue.
The issue was not in video but in audio.
I had audio devices opened in the service. Closing the service and sending
B4X:
 Dim r As Reflector
    r.Target = audioStream
    r.Target = r.GetField("audioRecord")
    r.RunMethod("release")

Solved the issue.

Ciao
Mauro
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Just to know, are you streaming real time audio? If so, from device to server or device to device?

I want to do something similar, but facing delay and bandwidth issues when there is not wifi
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
In this case device to server or better device to operator, using an ACD based system, multi operators and almost unlimited devices. We stream audio and video. Delays are not so high and audio is bidirectional, compressed in a home made way(inflation/deflation). The stream from device is delayed but not too much... The audio from Windows is almost real time. The whole system is covered with a patent. I'm collaborating with many software houses for both Android and Iphone. I write problematic parts of APP. I get fun and money too! After 42 years in IT, from micro's to large systems, I can figure a solution in minutes.
Ciao
Mauro
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
That sounds promising! Hope we are not doing the same ... just joking :D. My app intends to be a kind of group chat and gaming zone

I have also been for many years working from microcontrollers to large systems, in fact I still do some small projects involving HW and SW, I like it.


In my case I compress the camera preview with a RLE schema (not jpeg, but really fast and acceptable compression ratio), and transmit about one frame each second. It works fine "in the lab" but there is a lot to do on the server side. The current one works on a tablet and also made it with B4A, but now I have to work on it for a PC.


Good luck and let us know when it is ready! I'm curious about it!
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
It will be released in one or two weeks. We work with Jpg, the compression is fast and on server side is simple to decode. The server works in 5 threads and decode audio and video, plus a stream of data, like real time GPS and commands. We use 3 streams, plus some Web service. I'll tell you about the use later. Do you have commercial power in Spain? My partner has an outsourcing company so they will outsource a service, which could be selled in Spain and any other place. We'll talk in private later... Ciao!
 
Upvote 0

rbirago

Active Member
Licensed User
Longtime User
Hi, in these days I'm starting to try RSVideoRecord and I've followed the Tigrot'samples. No problem with preview, but when I call record.start it gives me an error "start failed" (see attached log). Perhaps the record's settings don't match with my smartphone? (Android 4.2.2). What can I check for? Really also the other B4A samples I've found in the blog don't work. Any suggestion?
thanks
Roberto
 

Attachments

  • RSRecordView Start error.png
    RSRecordView Start error.png
    32.6 KB · Views: 261
Upvote 0
Top