Exemplo n.º 1
0
    def _on_stream_video_mpegts(self, request, camera_name):
        encoder_queue = Queue(1)
        subscriptions = {
            self._cameras[camera_name].mpegts_reader: encoder_queue
        }
        encoder = MpegTS(camera_name, self._stop_events[0], self._log_queue, encoder_queue,
                         self._cameras[camera_name].mpegts_buffer, subscriptions,
                         kwargs={'log_level': self._args.log_level})

        response = Response(encoder, mimetype=encoder.mime_type)
        response.call_on_close(encoder.close)
        return response
Exemplo n.º 2
0
    def _on_stream_video_mjpeg(self, request, camera_name):
        encoder_queue = Queue(1)
        subscriptions = {
            self._cameras[camera_name].sieve: self._cameras[camera_name].visual_effects_queue,
            self._cameras[camera_name].visual_effects: encoder_queue
        }
        encoder = MotionJpeg(camera_name, self._stop_events[0], self._log_queue, encoder_queue,
                             self._cameras[camera_name].frame_buffer_out,
                             self._cameras[camera_name].jpeg_encoder_buffer, subscriptions,
                             kwargs={'log_level': self._args.log_level})

        response = Response(encoder, mimetype=encoder.mime_type)
        response.call_on_close(encoder.close)
        return response
Exemplo n.º 3
0
    def _parse_and_execute(self, process, wps_request, uuid):
        """Parse and execute request
        """
        LOGGER.debug('Checking if datainputs is required and has been passed')
        if process.inputs:
            if wps_request.inputs is None:
                raise MissingParameterValue('', 'datainputs')

        LOGGER.debug('Checking if all mandatory inputs have been passed')
        data_inputs = {}
        for inpt in process.inputs:
            if inpt.identifier not in wps_request.inputs:
                if inpt.min_occurs > 0:
                    LOGGER.error('Missing parameter value: %s', inpt.identifier)
                    raise MissingParameterValue(
                        inpt.identifier, inpt.identifier)
                else:
                    inputs = deque(maxlen=inpt.max_occurs)
                    inputs.append(inpt.clone())
                    data_inputs[inpt.identifier] = inputs

            # Replace the dicts with the dict of Literal/Complex inputs
            # set the input to the type defined in the process
            if isinstance(inpt, ComplexInput):
                data_inputs[inpt.identifier] = self.create_complex_inputs(
                    inpt, wps_request.inputs[inpt.identifier])
            elif isinstance(inpt, LiteralInput):
                data_inputs[inpt.identifier] = self.create_literal_inputs(
                    inpt, wps_request.inputs[inpt.identifier])
            elif isinstance(inpt, BoundingBoxInput):
                data_inputs[inpt.identifier] = self.create_bbox_inputs(
                    inpt, wps_request.inputs[inpt.identifier])

        wps_request.inputs = data_inputs

        # set as_reference to True for all the outputs specified as reference
        # if the output is not required to be raw
        if not wps_request.raw:
            for wps_outpt in wps_request.outputs:

                is_reference = wps_request.outputs[
                    wps_outpt].get('asReference', 'false')
                if is_reference.lower() == 'true':
                    # check if store is supported
                    if process.store_supported == 'false':
                        raise StorageNotSupported(
                            'The storage of data is not supported for this process.')

                    is_reference = True
                else:
                    is_reference = False

                for outpt in process.outputs:
                    if outpt.identifier == wps_outpt:
                        outpt.as_reference = is_reference

        # catch error generated by process code
        try:
            wps_response = process.execute(wps_request, uuid)
        except Exception as e:
            if not isinstance(e, NoApplicableCode):
                raise NoApplicableCode('Service error: %s' % e)
            raise e

        # get the specified output as raw
        if wps_request.raw:
            for outpt in wps_request.outputs:
                for proc_outpt in process.outputs:
                    if outpt == proc_outpt.identifier:
                        resp = Response(proc_outpt.data)
                        resp.call_on_close(process.clean)
                        return resp

            # if the specified identifier was not found raise error
            raise InvalidParameterValue('')

        return wps_response
Exemplo n.º 4
0
    def _parse_and_execute(self, process, wps_request, uuid):
        """Parse and execute request
        """

        LOGGER.debug('Checking if all mandatory inputs have been passed')
        data_inputs = {}
        for inpt in process.inputs:
            # Replace the dicts with the dict of Literal/Complex inputs
            # set the input to the type defined in the process.

            request_inputs = None
            if inpt.identifier in wps_request.inputs:
                request_inputs = wps_request.inputs[inpt.identifier]

            if not request_inputs:
                if inpt.data_set:
                    data_inputs[inpt.identifier] = [inpt.clone()]
            else:

                if isinstance(inpt, ComplexInput):
                    data_inputs[inpt.identifier] = self.create_complex_inputs(
                        inpt, request_inputs)
                elif isinstance(inpt, LiteralInput):
                    data_inputs[inpt.identifier] = self.create_literal_inputs(
                        inpt, request_inputs)
                elif isinstance(inpt, BoundingBoxInput):
                    data_inputs[inpt.identifier] = self.create_bbox_inputs(
                        inpt, request_inputs)

        for inpt in process.inputs:

            if inpt.identifier not in data_inputs:
                if inpt.min_occurs > 0:
                    LOGGER.error('Missing parameter value: %s',
                                 inpt.identifier)
                    raise MissingParameterValue(inpt.identifier,
                                                inpt.identifier)

        wps_request.inputs = data_inputs

        # set as_reference to True for all the outputs specified as reference
        # if the output is not required to be raw
        if not wps_request.raw:
            for wps_outpt in wps_request.outputs:

                is_reference = wps_request.outputs[wps_outpt].get(
                    'asReference', 'false')
                if is_reference.lower() == 'true':
                    # check if store is supported
                    if process.store_supported == 'false':
                        raise StorageNotSupported(
                            'The storage of data is not supported for this process.'
                        )

                    is_reference = True
                else:
                    is_reference = False

                for outpt in process.outputs:
                    if outpt.identifier == wps_outpt:
                        outpt.as_reference = is_reference

        # catch error generated by process code
        try:
            wps_response = process.execute(wps_request, uuid)
        except Exception as e:
            e_follow = e
            if not isinstance(e, NoApplicableCode):
                e_follow = NoApplicableCode('Service error: %s' % e)
            if wps_request.raw:
                resp = Response(e_follow.get_body(),
                                mimetype='application/xml')
                resp.call_on_close(process.clean)
                return resp
            else:
                raise e_follow

        # get the specified output as raw
        if wps_request.raw:
            for outpt in wps_request.outputs:
                for proc_outpt in process.outputs:
                    if outpt == proc_outpt.identifier:
                        return Response(proc_outpt.data)

            # if the specified identifier was not found raise error
            raise InvalidParameterValue('')

        return wps_response