def start(request): if request.method == 'POST': form = StreamForm(request.POST) if form.is_valid(): # Source Info source_obj = form.cleaned_data['sources'] sId = source_obj.id sType = source_obj.type sDevice = source_obj.device sInput = source_obj.input sChannelList = source_obj.channelList # File Info file = form.cleaned_data['files'] if file: fileName=os.path.split(file)[-1] else: fileName='' if source_obj.channelList: channelId = form.cleaned_data['channels'] c=Channel.objects.get(id=channelId) else: channelId = '' # Stream Info dstObjs = form.cleaned_data['destinations'] # Tune Capture Card and Start Stream # Handle Different Source Types if sType == "file": mediafile=os.path.join(sDevice, file) #pid=9999 pid=vlc.startStream(mediafile, dstObjs) elif sType == "ivtv": vlc.v4l2ctl(sInput, sDevice) if channelId: vlc.ivtvTune(sDevice, c.number, c.modulation) pvrDevice="pvr:/"+sDevice pid=vlc.startStream(pvrDevice, dstObjs) elif sType == "dvb": pid=vlc.startStream(sDevice, dstObjs, c.frequency, c.program, c.modulation) # Get destination IDs to store into DB dstIds=','.join([ str(dst.id) for dst in dstObjs ]) # Temporary PID s = ActiveStream(pid=pid, sourceId=sId, channelId=channelId, fileName=fileName, dstIds=dstIds, time=datetime.datetime.now()) s.save() #return HttpResponse(str(pid)) return HttpResponseRedirect(reverse('streamer.views.index')) else: form = StreamForm() return render_to_response('streamer/start.html', {'form':form,}, context_instance=RequestContext(request))
def change(request, stream_id, channelId): '''Change the TV Channel''' streamObj = get_object_or_404(ActiveStream, id=stream_id) sourceObj = get_object_or_404(Source, id=streamObj.sourceId) sType = sourceObj.type sDevice = sourceObj.device c = get_object_or_404(Channel, id=channelId) if sType == 'ivtv': vlc.ivtvTune(sDevice, c.number, c.modulation) streamObj.channelId = channelId streamObj.save() # Restart VLC, yuck elif sType == 'dvb': # Get Active Stream destinations dstIds = str(streamObj.dstIds).split(',') # Get all active stream dst objects dstObjs = [Destination.objects.get(id=dstId) for dstId in dstIds] # Kill Stream if DEBUG_CMD: print "Kill " + str(streamObj.pid) else: # Issue Kill Command # Wait 10 seconds for VLC to close os.kill(streamObj.pid, 15) fin_time = time.time() + 10 # wait a max of 10 seconds while time.time() < fin_time: try: os.kill(streamObj.pid, 0) except OSError: break time.sleep(0.1) # Start Stream pid = vlc.startStream(sDevice, dstObjs, c.frequency, c.program, c.modulation) # Update Channel ID & PID streamObj.channelId = channelId streamObj.pid = pid streamObj.save() else: return HttpResponseBadRequest('Can\'t change channel for source: ' + input_type) return HttpResponse('Channel Changed')
def change(request, stream_id, channelId): '''Change the TV Channel''' streamObj=get_object_or_404(ActiveStream,id=stream_id) sourceObj=get_object_or_404(Source,id=streamObj.sourceId) sType=sourceObj.type sDevice=sourceObj.device c=get_object_or_404(Channel,id=channelId) if sType == 'ivtv': vlc.ivtvTune(sDevice, c.number, c.modulation) streamObj.channelId=channelId streamObj.save() # Restart VLC, yuck elif sType == 'dvb': # Get Active Stream destinations dstIds=str(streamObj.dstIds).split(',') # Get all active stream dst objects dstObjs=[ Destination.objects.get(id=dstId) for dstId in dstIds ] # Kill Stream if DEBUG_CMD: print "Kill " + str(streamObj.pid) else: # Issue Kill Command # Wait 10 seconds for VLC to close os.kill(streamObj.pid, 15) fin_time = time.time() + 10 # wait a max of 10 seconds while time.time() < fin_time: try: os.kill(streamObj.pid,0) except OSError: break time.sleep(0.1) # Start Stream pid=vlc.startStream(sDevice, dstObjs, c.frequency, c.program, c.modulation) # Update Channel ID & PID streamObj.channelId=channelId streamObj.pid=pid streamObj.save() else: return HttpResponseBadRequest('Can\'t change channel for source: ' + input_type) return HttpResponse('Channel Changed')
def start(request): if request.method == 'POST': form = StreamForm(request.POST) if form.is_valid(): # Source Info source_obj = form.cleaned_data['sources'] sId = source_obj.id sType = source_obj.type sDevice = source_obj.device sInput = source_obj.input sChannelList = source_obj.channelList # File Info file = form.cleaned_data['files'] if file: fileName = os.path.split(file)[-1] else: fileName = '' if source_obj.channelList: channelId = form.cleaned_data['channels'] c = Channel.objects.get(id=channelId) else: channelId = '' # Stream Info dstObjs = form.cleaned_data['destinations'] # Tune Capture Card and Start Stream # Handle Different Source Types if sType == "file": mediafile = os.path.join(sDevice, file) #pid=9999 pid = vlc.startStream(mediafile, dstObjs) elif sType == "ivtv": vlc.v4l2ctl(sInput, sDevice) if channelId: vlc.ivtvTune(sDevice, c.number, c.modulation) pvrDevice = "pvr:/" + sDevice pid = vlc.startStream(pvrDevice, dstObjs) elif sType == "dvb": pid = vlc.startStream(sDevice, dstObjs, c.frequency, c.program, c.modulation) # Get destination IDs to store into DB dstIds = ','.join([str(dst.id) for dst in dstObjs]) # Temporary PID s = ActiveStream(pid=pid, sourceId=sId, channelId=channelId, fileName=fileName, dstIds=dstIds, time=datetime.datetime.now()) s.save() #return HttpResponse(str(pid)) return HttpResponseRedirect(reverse('streamer.views.index')) else: form = StreamForm() return render_to_response('streamer/start.html', { 'form': form, }, context_instance=RequestContext(request))