Exemple #1
0
TEST(Parser, ParseMatrix)
{
  std::stringstream read_in("2 3 1 2/5 3 -4 5 -6/2");
  MatrixQ result;
  EXPECT_TRUE(parse_matrix(read_in, result));
  MatrixQ expected = {{1_mpq, 2/5_mpq, 3_mpq}, {-4_mpq, 5_mpq, -6/2_mpq}};
  EXPECT_EQ(expected, result);
}
Exemple #2
0
// Allocate memory and set function pointers
static int af_open(struct af_instance *af)
{
    af->control = control;
    af->filter_frame = filter_frame;
    af_pan_t *s = af->priv;
    int nch = s->nch;
    if (nch && AF_OK != control(af, AF_CONTROL_SET_PAN_NOUT, &nch))
        return AF_ERROR;

    // Read pan values
    if (s->matrixstr)
        parse_matrix(af, s->matrixstr);
    return AF_OK;
}
Exemple #3
0
// Initialization and runtime control
static int control(struct af_instance *af, int cmd, void *arg)
{
    af_pan_t* s = af->priv;

    switch(cmd){
    case AF_CONTROL_REINIT:
        // Sanity check
        if (!arg)
            return AF_ERROR;

        af->data->rate = ((struct mp_audio*)arg)->rate;
        mp_audio_set_format(af->data, AF_FORMAT_FLOAT);
        set_channels(af->data, s->nch ? s->nch : ((struct mp_audio*)arg)->nch);

        if ((af->data->format != ((struct mp_audio*)arg)->format) ||
            (af->data->bps != ((struct mp_audio*)arg)->bps)) {
            mp_audio_set_format((struct mp_audio*)arg, af->data->format);
            return AF_FALSE;
        }
        return AF_OK;
    case AF_CONTROL_SET_PAN_LEVEL: {
        int    i;
        int    ch = ((af_control_ext_t*)arg)->ch;
        float  *level = ((af_control_ext_t*)arg)->arg;
        if (ch >= AF_NCH)
            return AF_FALSE;
        for (i = 0; i < AF_NCH; i++)
            s->level[ch][i] = level[i];
        return AF_OK;
    }
    case AF_CONTROL_SET_PAN_NOUT:
        // Reinit must be called after this function has been called
        // Sanity check
        if (((int*)arg)[0] <= 0 || ((int*)arg)[0] > AF_NCH) {
            MP_ERR(af, "The number of output channels must be"
                       " between 1 and %i. Current value is %i\n",
                       AF_NCH, ((int*)arg)[0]);
            return AF_ERROR;
        }
        s->nch = ((int*)arg)[0];
        return AF_OK;
    case AF_CONTROL_SET_PAN_BALANCE: {
        float val = *(float*)arg;
        if (s->nch)
            return AF_ERROR;
        if (af->data->nch >= 2) {
            s->level[0][0] = MPMIN(1.f, 1.f - val);
            s->level[0][1] = MPMAX(0.f, val);
            s->level[1][0] = MPMAX(0.f, -val);
            s->level[1][1] = MPMIN(1.f, 1.f + val);
        }
        return AF_OK;
    }
    case AF_CONTROL_GET_PAN_BALANCE:
        if (s->nch)
            return AF_ERROR;
        *(float*)arg = s->level[0][1] - s->level[1][0];
        return AF_OK;
    case AF_CONTROL_COMMAND: {
        char **args = arg;
        if (!strcmp(args[0], "set-matrix")) {
            parse_matrix(af, args[1]);
            return CONTROL_OK;
        } else {
            return CONTROL_ERROR;
        }
    }
    }
    return AF_UNKNOWN;
}
Exemple #4
0
// *************************************************************************************
// MAIN
// *************************************************************************************
int main (int argc, char *argv[])
{

	int verbose = 4; // LOG_ERROR ;
	int fdIn = 0 ;
	int fdOut = 1 ;
	y4m_stream_info_t in_streaminfo,out_streaminfo;
	const static char *legal_flags = "d:m:V:";
	int c, *matrix,matlen;
	float divisor=0;

  while ((c = getopt (argc, argv, legal_flags)) != -1) {
    switch (c) {
      case 'V':
        verbose = atoi (optarg);
        if (verbose < 0 || verbose > 2)
          mjpeg_error_exit1 ("Verbose level must be [0..2]");
        break;
    case 'd':
	    divisor = atof(optarg);
		if (divisor == 0) {
			mjpeg_error_exit1 ("Divisor must not be 0");
		}

		break;
	case 'm':
		// strlen should be longer than the
		matrix = (int *) malloc (sizeof(int) * strlen(optarg));
		matlen = parse_matrix(optarg,matrix);
		if (matlen == 0) {
			mjpeg_error_exit1 ("Invalid matrix");
		}
		break;

	case '?':
          print_usage (argv);
          return 0 ;
          break;
    }
  }

	if (divisor == 0) {
		divisor = sum_matrix(matrix,matlen);
	}

	if (divisor == 0) {
		mjpeg_warn("divisor defaulting to 1\n");
		divisor = 1;
	}

  // mjpeg tools global initialisations
  mjpeg_default_handler_verbosity (verbose);

  // Initialize input streams
  y4m_init_stream_info (&in_streaminfo);
  y4m_init_stream_info (&out_streaminfo);

  // ***************************************************************
  // Get video stream informations (size, framerate, interlacing, aspect ratio).
  // The streaminfo structure is filled in
  // ***************************************************************
  // INPUT comes from stdin, we check for a correct file header
	if (y4m_read_stream_header (fdIn, &in_streaminfo) != Y4M_OK)
		mjpeg_error_exit1 ("Could'nt read YUV4MPEG header!");

	y4m_ratio_t src_frame_rate = y4m_si_get_framerate( &in_streaminfo );
	y4m_copy_stream_info( &out_streaminfo, &in_streaminfo );

  // Information output
  mjpeg_info ("yuvconvolve (version " YUVRFPS_VERSION ") performs a convolution matrix on yuv streams");
  mjpeg_info ("yuvconvolve -? for help");

	y4m_write_stream_header(fdOut,&out_streaminfo);

  /* in that function we do all the important work */

  fprintf (stderr,"matrix square: %d\n",matlen);

	convolve( fdIn,&in_streaminfo,fdOut,&out_streaminfo,matrix,divisor,matlen);

  y4m_fini_stream_info (&in_streaminfo);
  y4m_fini_stream_info (&out_streaminfo);

  return 0;
}