Esempio n. 1
0
static void
test_buffers_are_contigous (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  GstElement *p =
      gst_parse_launch
      ("buzztrax-test-audio-synth name=\"src\" num-buffers=2 ! fakesink async=false",
      NULL);
  BtTestAudioSynth *e =
      (BtTestAudioSynth *) gst_bin_get_by_name (GST_BIN (p), "src");
  GstBus *bus = gst_element_get_bus (p);

  GST_INFO ("-- act --");
  gst_element_set_state (p, GST_STATE_PLAYING);
  gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, GST_CLOCK_TIME_NONE);

  GST_INFO ("-- assert --");
  BufferFields *bf0 = get_buffer_info (e, 0);
  BufferFields *bf1 = get_buffer_info (e, 1);
  ck_assert_uint64_eq (bf1->ts, bf0->ts + bf0->duration);
  ck_assert_uint64_eq (bf1->offset, bf0->offset + bf0->offset_end);

  GST_INFO ("-- cleanup --");
  gst_element_set_state (p, GST_STATE_NULL);
  gst_object_unref (e);
  gst_object_unref (p);
  BT_TEST_END;
}
Esempio n. 2
0
static void
test_position_query_time (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  GstElement *p =
      gst_parse_launch
      ("buzztrax-test-audio-synth name=\"src\" num-buffers=1 ! fakesink async=false",
      NULL);
  BtTestAudioSynth *e =
      (BtTestAudioSynth *) gst_bin_get_by_name (GST_BIN (p), "src");
  GstBus *bus = gst_element_get_bus (p);

  GST_INFO ("-- act --");
  gst_element_set_state (p, GST_STATE_PLAYING);
  gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, GST_CLOCK_TIME_NONE);

  GST_INFO ("-- assert --");
  BufferFields *bf = get_buffer_info (e, 0);
  gint64 pos;
  gboolean res = gst_element_query_position ((GstElement *) e, GST_FORMAT_TIME,
      &pos);
  fail_unless (res, NULL);
  ck_assert_uint64_eq (bf->duration, pos);

  GST_INFO ("-- cleanup --");
  gst_element_set_state (p, GST_STATE_NULL);
  gst_object_unref (e);
  gst_object_unref (p);
  BT_TEST_END;
}
Esempio n. 3
0
static void
test_audio_context_configures_buffer_size (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  GstElement *p =
      gst_parse_launch
      ("buzztrax-test-audio-synth name=\"src\" num-buffers=1 ! fakesink async=false",
      NULL);
  BtTestAudioSynth *e =
      (BtTestAudioSynth *) gst_bin_get_by_name (GST_BIN (p), "src");
  GstBus *bus = gst_element_get_bus (p);

  GST_INFO ("-- act --");
  gst_element_set_state (p, GST_STATE_READY);
  gst_element_set_context (p, ctx);
  gst_element_set_state (p, GST_STATE_PLAYING);
  gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, GST_CLOCK_TIME_NONE);

  GST_INFO ("-- assert --");
  BufferFields *bf = get_buffer_info (e, 0);
  // sizeof(gint16) * (int)(0.5 + (44100 * (60.0 / 8)) / (120 * 4))
  ck_assert_uint_eq (bf->size, 1378);

  GST_INFO ("-- cleanup --");
  gst_element_set_state (p, GST_STATE_NULL);
  gst_object_unref (bus);
  gst_object_unref (e);
  gst_object_unref (p);
  BT_TEST_END;
}
Esempio n. 4
0
void
record_string(int nStrType, char* pBuffer, int nStrLen){
	FILE* 		pFileTmp = NULL;
	char		szBufInfo[MAX_BUF_2048];
	int		nLen;
	
	switch( nStrType ){
	case STR_NORMAL:
		pFileTmp = g_strFile;
		break;
	case STR_PATH:
		pFileTmp = g_pathFile;
		break;
	case STR_ERROR:
		pFileTmp = g_errFile;
		break;
	case STR_FILE_NAME:
		pFileTmp = g_fileNameFile;
		break;
	}

	if ( pFileTmp == NULL )
		return;

	fwrite(pBuffer, 1, nStrLen, pFileTmp);
	fwrite("\n", 1, 1, pFileTmp);

	/* record the string position info
	   when it is recognized as a non-normal string */
	if ( nStrType != STR_NORMAL ){
		nLen = get_buffer_info(szBufInfo);
		fwrite(szBufInfo, 1, nLen, pFileTmp);
		fwrite("\n", 1, 1, pFileTmp);
	}
}
Esempio n. 5
0
static void
test_last_buffer_is_clipped (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  GstElement *p =
      gst_parse_launch
      ("buzztrax-test-audio-synth name=\"src\" ! fakesink async=false",
      NULL);
  BtTestAudioSynth *e =
      (BtTestAudioSynth *) gst_bin_get_by_name (GST_BIN (p), "src");
  GstBus *bus = gst_element_get_bus (p);

  GST_INFO ("-- act --");
  gst_element_set_state (p, GST_STATE_READY);
  gst_element_set_context (p, ctx);
  gst_element_set_state (p, GST_STATE_PAUSED);
  gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
  gst_element_seek (p, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
      GST_SEEK_TYPE_SET, G_GUINT64_CONSTANT (0),
      GST_SEEK_TYPE_SET, ticktime * 1.5);
  gst_element_set_state (p, GST_STATE_PLAYING);
  gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
  gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, GST_CLOCK_TIME_NONE);

  GST_INFO ("-- assert --");
  BufferFields *bf0 = get_buffer_info (e, 0);
  BufferFields *bf1 = get_buffer_info (e, 1);
  ck_assert_uint64_le (bf1->duration, bf0->duration / 2);
  ck_assert_uint_le (bf1->size, bf0->size / 2);

  GST_INFO ("-- cleanup --");
  gst_element_set_state (p, GST_STATE_NULL);
  gst_object_unref (e);
  gst_object_unref (p);
  BT_TEST_END;
}
Esempio n. 6
0
static void
test_backwards_last_buffer_ends_at_zero (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  GstElement *p =
      gst_parse_launch
      ("buzztrax-test-audio-synth name=\"src\" num-buffers=1 ! fakesink async=false",
      NULL);
  BtTestAudioSynth *e =
      (BtTestAudioSynth *) gst_bin_get_by_name (GST_BIN (p), "src");
  GstBus *bus = gst_element_get_bus (p);

  GST_INFO ("-- act --");
  gst_element_set_state (p, GST_STATE_READY);
  gst_element_set_context (p, ctx);
  gst_element_set_state (p, GST_STATE_PAUSED);
  gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
  gst_element_seek (p, -1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
      GST_SEEK_TYPE_SET, G_GUINT64_CONSTANT (0), GST_SEEK_TYPE_SET, ticktime);
  gst_element_set_state (p, GST_STATE_PLAYING);
  gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
  gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, GST_CLOCK_TIME_NONE);

  GST_INFO ("-- assert --");
  BufferFields *bf = get_buffer_info (e, 0);
  ck_assert_uint64_eq (bf->ts, 0);
  ck_assert_uint64_eq (bf->offset, 0);

  GST_INFO ("-- cleanup --");
  gst_element_set_state (p, GST_STATE_NULL);
  gst_object_unref (e);
  gst_object_unref (p);

  BT_TEST_END;
}
Esempio n. 7
0
/* get buffer info */
static int get_buffer_info(struct etna_bo *bo)
{
	struct drm_vivante_gem_info req = {
			.handle = bo->handle,
	};
	int ret = drmCommandWriteRead(bo->dev->fd, DRM_VIVANTE_GEM_INFO,
			&req, sizeof(req));
	if (ret) {
		return ret;
	}

	/* really all we need for now is mmap offset */
	bo->offset = req.offset;

	return 0;
}

/* import a buffer object from DRI2 name */
struct etna_bo * etna_bo_from_name(struct etna_device *dev, uint32_t name)
{
	struct drm_gem_open req = {
			.name = name,
	};
	struct etna_bo *bo;

	pthread_mutex_lock(&table_lock);

	/* check name table first, to see if bo is already open: */
	bo = lookup_bo(dev, req.handle);
	if (bo)
		goto out_unlock;

	if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) {
		ERROR_MSG("gem-open failed: %s", strerror(errno));
		goto out_unlock;
	}

	bo = lookup_bo(dev, req.handle);
	if (bo)
		goto out_unlock;

	bo = bo_from_handle(dev, req.size, req.handle);
	if (bo)
		set_name(bo, name);

out_unlock:
	pthread_mutex_unlock(&table_lock);

	return bo;
}

/* import a buffer from dmabuf fd, does not take ownership of the
 * fd so caller should close() the fd when it is otherwise done
 * with it (even if it is still using the 'struct etna_bo *')
 */
struct etna_bo * etna_bo_from_dmabuf(struct etna_device *dev, int fd)
{
#if 0
	struct etna_bo *bo = NULL;
	struct drm_prime_handle req = {
			.fd = fd,
	};
	int ret;

	pthread_mutex_lock(&table_lock);

	ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
	if (ret) {
		goto fail;
	}

	bo = lookup_bo(dev, req.handle);
	if (!bo) {
		bo = bo_from_handle(dev, req.handle);
	}

	pthread_mutex_unlock(&table_lock);

	return bo;

fail:
	pthread_mutex_unlock(&table_lock);
	free(bo);
#endif
	return NULL;
}

/* destroy a buffer object */
void etna_bo_del(struct etna_bo *bo)
{
	if (!bo)
		return;

	if (!atomic_dec_and_test(&bo->refcnt))
		return;

	if (bo->map)
		munmap(bo->map, bo->size);

	if (bo->fd)
		close(bo->fd);

	if (bo->handle) {
		struct drm_gem_close req = {
				.handle = bo->handle,
		};
		pthread_mutex_lock(&table_lock);
		drmHashDelete(bo->dev->handle_table, bo->handle);
		drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
		pthread_mutex_unlock(&table_lock);
	}

	etna_device_del(bo->dev);

	free(bo);
}

/* get the global flink/DRI2 buffer name */
int etna_bo_get_name(struct etna_bo *bo, uint32_t *name)
{
	if (!bo->name) {
		struct drm_gem_flink req = {
				.handle = bo->handle,
		};
		int ret;

		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req);
		if (ret) {
			return ret;
		}

		bo->name = req.name;
	}

	*name = bo->name;

	return 0;
}

uint32_t etna_bo_handle(struct etna_bo *bo)
{
	return bo->handle;
}

/* caller owns the dmabuf fd that is returned and is responsible
 * to close() it when done
 */
int etna_bo_dmabuf(struct etna_bo *bo)
{
	if (!bo->fd) {
		struct drm_prime_handle req = {
				.handle = bo->handle,
				.flags = DRM_CLOEXEC,
		};
		int ret;

		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
		if (ret) {
			return ret;
		}

		bo->fd = req.fd;
	}
	return dup(bo->fd);
}

uint32_t etna_bo_size(struct etna_bo *bo)
{
	if (!bo->size) {
		get_buffer_info(bo);
	}
	return bo->size;
}

void * etna_bo_map(struct etna_bo *bo)
{
	if (!bo->map) {
		if (!bo->offset) {
			get_buffer_info(bo);
		}

		bo->map = mmap(0, bo->size, PROT_READ | PROT_WRITE,
				MAP_SHARED, bo->dev->fd, bo->offset);
		if (bo->map == MAP_FAILED) {
			bo->map = NULL;
		}
	}
	return bo->map;
}

int etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op)
{
	return 0;
}

void etna_bo_cpu_fini(struct etna_bo *bo)
{
}
Esempio n. 8
0
/* get buffer info */
static int get_buffer_info(struct omap_bo *bo)
{
	struct drm_omap_gem_info req = {
			.handle = bo->handle,
	};
	int ret = drmCommandWriteRead(bo->dev->fd, DRM_OMAP_GEM_INFO,
			&req, sizeof(req));
	if (ret) {
		return ret;
	}

	/* really all we need for now is mmap offset */
	bo->offset = req.offset;
	bo->size = req.size;

	return 0;
}

/* import a buffer object from DRI2 name */
drm_public struct omap_bo *
omap_bo_from_name(struct omap_device *dev, uint32_t name)
{
	struct omap_bo *bo = NULL;
	struct drm_gem_open req = {
			.name = name,
	};

	pthread_mutex_lock(&table_lock);

	if (drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req)) {
		goto fail;
	}

	bo = lookup_bo(dev, req.handle);
	if (!bo) {
		bo = bo_from_handle(dev, req.handle);
		bo->name = name;
	}

	pthread_mutex_unlock(&table_lock);

	return bo;

fail:
	pthread_mutex_unlock(&table_lock);
	free(bo);
	return NULL;
}

/* import a buffer from dmabuf fd, does not take ownership of the
 * fd so caller should close() the fd when it is otherwise done
 * with it (even if it is still using the 'struct omap_bo *')
 */
drm_public struct omap_bo *
omap_bo_from_dmabuf(struct omap_device *dev, int fd)
{
	struct omap_bo *bo = NULL;
	struct drm_prime_handle req = {
			.fd = fd,
	};
	int ret;

	pthread_mutex_lock(&table_lock);

	ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
	if (ret) {
		goto fail;
	}

	bo = lookup_bo(dev, req.handle);
	if (!bo) {
		bo = bo_from_handle(dev, req.handle);
	}

	pthread_mutex_unlock(&table_lock);

	return bo;

fail:
	pthread_mutex_unlock(&table_lock);
	free(bo);
	return NULL;
}

/* destroy a buffer object */
drm_public void omap_bo_del(struct omap_bo *bo)
{
	if (!bo) {
		return;
	}

	if (!atomic_dec_and_test(&bo->refcnt))
		return;

	if (bo->map) {
		munmap(bo->map, bo->size);
	}

	if (bo->fd >= 0) {
		close(bo->fd);
	}

	if (bo->handle) {
		struct drm_gem_close req = {
				.handle = bo->handle,
		};
		pthread_mutex_lock(&table_lock);
		drmHashDelete(bo->dev->handle_table, bo->handle);
		drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
		pthread_mutex_unlock(&table_lock);
	}

	omap_device_del(bo->dev);

	free(bo);
}

/* get the global flink/DRI2 buffer name */
drm_public int omap_bo_get_name(struct omap_bo *bo, uint32_t *name)
{
	if (!bo->name) {
		struct drm_gem_flink req = {
				.handle = bo->handle,
		};
		int ret;

		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req);
		if (ret) {
			return ret;
		}

		bo->name = req.name;
	}

	*name = bo->name;

	return 0;
}

drm_public uint32_t omap_bo_handle(struct omap_bo *bo)
{
	return bo->handle;
}

/* caller owns the dmabuf fd that is returned and is responsible
 * to close() it when done
 */
drm_public int omap_bo_dmabuf(struct omap_bo *bo)
{
	if (bo->fd < 0) {
		struct drm_prime_handle req = {
				.handle = bo->handle,
				.flags = DRM_CLOEXEC,
		};
		int ret;

		ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
		if (ret) {
			return ret;
		}

		bo->fd = req.fd;
	}
	return dup(bo->fd);
}

drm_public uint32_t omap_bo_size(struct omap_bo *bo)
{
	if (!bo->size) {
		get_buffer_info(bo);
	}
	return bo->size;
}

drm_public void *omap_bo_map(struct omap_bo *bo)
{
	if (!bo->map) {
		if (!bo->offset) {
			get_buffer_info(bo);
		}

		bo->map = mmap(0, bo->size, PROT_READ | PROT_WRITE,
				MAP_SHARED, bo->dev->fd, bo->offset);
		if (bo->map == MAP_FAILED) {
			bo->map = NULL;
		}
	}
	return bo->map;
}

drm_public int omap_bo_cpu_prep(struct omap_bo *bo, enum omap_gem_op op)
{
	struct drm_omap_gem_cpu_prep req = {
			.handle = bo->handle,
			.op = op,
	};
	return drmCommandWrite(bo->dev->fd,
			DRM_OMAP_GEM_CPU_PREP, &req, sizeof(req));
}

drm_public int omap_bo_cpu_fini(struct omap_bo *bo, enum omap_gem_op op)
{
	struct drm_omap_gem_cpu_fini req = {
			.handle = bo->handle,
			.op = op,
			.nregions = 0,
	};
	return drmCommandWrite(bo->dev->fd,
			DRM_OMAP_GEM_CPU_FINI, &req, sizeof(req));
}