MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compute

Method Compute

tensorflow/contrib/ffmpeg/encode_audio_op.cc:63–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61 explicit EncodeAudioOpV2(OpKernelConstruction* context) : OpKernel(context) {}
62
63 void Compute(OpKernelContext* context) override {
64 OP_REQUIRES(
65 context, context->num_inputs() == 4,
66 errors::InvalidArgument("EncodeAudio requires exactly four inputs."));
67
68 const Tensor& contents = context->input(0);
69 const Tensor& file_format_tensor = context->input(1);
70 const Tensor& samples_per_second_tensor = context->input(2);
71 const Tensor& bits_per_second_tensor = context->input(3);
72
73 OP_REQUIRES(context, TensorShapeUtils::IsMatrix(contents.shape()),
74 errors::InvalidArgument(
75 "sampled_audio must be a rank-2 tensor but got shape ",
76 contents.shape().DebugString()));
77 OP_REQUIRES(
78 context, contents.NumElements() <= std::numeric_limits<int32>::max(),
79 errors::InvalidArgument(
80 "sampled_audio cannot have more than 2^31 entries. Shape = ",
81 contents.shape().DebugString()));
82 OP_REQUIRES(context, TensorShapeUtils::IsScalar(file_format_tensor.shape()),
83 errors::InvalidArgument(
84 "file_format must be a rank-0 tensor but got shape ",
85 file_format_tensor.shape().DebugString()));
86 OP_REQUIRES(context,
87 TensorShapeUtils::IsScalar(samples_per_second_tensor.shape()),
88 errors::InvalidArgument(
89 "samples_per_second must be a rank-0 tensor but got shape ",
90 samples_per_second_tensor.shape().DebugString()));
91 OP_REQUIRES(context,
92 TensorShapeUtils::IsScalar(bits_per_second_tensor.shape()),
93 errors::InvalidArgument(
94 "bits_per_second must be a rank-0 tensor but got shape ",
95 bits_per_second_tensor.shape().DebugString()));
96
97 const string file_format =
98 absl::AsciiStrToLower(file_format_tensor.scalar<tstring>()());
99 const int32 samples_per_second =
100 samples_per_second_tensor.scalar<int32>()();
101 const int32 bits_per_second = bits_per_second_tensor.scalar<int32>()();
102
103 OP_REQUIRES(context, file_format == "wav",
104 errors::InvalidArgument(
105 "file_format must be \"wav\", but got: ", file_format));
106 OP_REQUIRES(context, samples_per_second > 0,
107 errors::InvalidArgument(
108 "samples_per_second must be positive, but got: ",
109 samples_per_second));
110 OP_REQUIRES(
111 context, bits_per_second > 0,
112 errors::InvalidArgument("bits_per_second must be positive, but got: ",
113 bits_per_second));
114
115 Encode(context, contents, file_format, bits_per_second, samples_per_second);
116 }
117};
118
119REGISTER_KERNEL_BUILDER(Name("EncodeAudioV2").Device(DEVICE_CPU),

Callers

nothing calls this directly

Calls 9

InvalidArgumentFunction · 0.85
EncodeFunction · 0.70
maxFunction · 0.50
IsScalarFunction · 0.50
num_inputsMethod · 0.45
inputMethod · 0.45
shapeMethod · 0.45
DebugStringMethod · 0.45
NumElementsMethod · 0.45

Tested by

no test coverage detected